The OpenD Programming Language

AliasSeq

Creates a sequence of zero or more aliases. This is most commonly used as template parameters or arguments.

In previous versions of Phobos, this was known as TypeTuple.

import std.meta;
alias AliasSeq(TList...) = TList

Examples

import std.meta;
alias TL = AliasSeq!(int, double);

int foo(TL td)  // same as int foo(int, double);
{
    return td[0] + cast(int) td[1];
}
alias TL = AliasSeq!(int, double);

alias Types = AliasSeq!(TL, char);
static assert(is(Types == AliasSeq!(int, double, char)));
// Creates a compile-time sequence of function call expressions
// that each call `func` with the next variadic template argument
template Map(alias func, args...)
{
    auto ref lazyItem() {return func(args[0]);}

    static if (args.length == 1)
    {
        alias Map = lazyItem;
    }
    else
    {
        // recurse
        alias Map = AliasSeq!(lazyItem, Map!(func, args[1 .. $]));
    }
}

static void test(int a, int b)
{
    assert(a == 4);
    assert(b == 16);
}

static int a = 2;
static int b = 4;

test(Map!(i => i ^^ 2, a, b));
assert(a == 2);
assert(b == 4);

test(Map!((ref i) => i *= i, a, b));
assert(a == 4);
assert(b == 16);

static void testRef(ref int a, ref int b)
{
    assert(a++ == 16);
    assert(b++ == 256);
}

testRef(Map!(function ref(ref i) => i *= i, a, b));
assert(a == 17);
assert(b == 257);

Meta