Skip to content

Commit

Permalink
Merge pull request #4882 from somzzz/issue_8799
Browse files Browse the repository at this point in the history
fix issue 8799
  • Loading branch information
andralex committed Nov 1, 2016
2 parents 00ce4ed + daf4d06 commit c77869f
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions std/meta.d
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,75 @@ template AliasSeq(TList...)
static assert(is(Types == AliasSeq!(int, double, char)));
}


/**
Returns an `AliasSeq` expression of `Func` being
applied to every variadic template argument.
*/

///
@safe unittest
{
auto ref ArgCall(alias Func, alias arg)()
{
return Func(arg);
}

template Map(alias Func, args...)
{
static if (args.length > 1)
{
alias Map = AliasSeq!(ArgCall!(Func, args[0]), Map!(Func, args[1 .. $]));
}
else
{
alias Map = ArgCall!(Func, args[0]);
}
}

static int square(int arg)
{
return arg * arg;
}

static int refSquare(ref int arg)
{
arg *= arg;
return arg;
}

static ref int refRetSquare(ref int arg)
{
arg *= arg;
return arg;
}

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

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

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

test(Map!(square, a, b));

test(Map!(refSquare, a, b));
assert(a == 4);
assert(b == 16);

testRef(Map!(refRetSquare, a, b));
assert(a == 17);
assert(b == 257);
}

/**
* Allows `alias`ing of any single symbol, type or compile-time expression.
*
Expand Down

0 comments on commit c77869f

Please sign in to comment.