Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 30 additions & 24 deletions std/meta.d
Original file line number Diff line number Diff line change
Expand Up @@ -1106,35 +1106,13 @@ unittest
*/
template ApplyLeft(alias Template, args...)
{
static if (args.length)
{
template ApplyLeft(right...)
{
static if (is(typeof(Template!(args, right))))
enum ApplyLeft = Template!(args, right); // values
else
alias ApplyLeft = Template!(args, right); // symbols
}
}
else
alias ApplyLeft = Template;
alias ApplyLeft(right...) = Template!(args, right);
}

/// Ditto
template ApplyRight(alias Template, args...)
{
static if (args.length)
{
template ApplyRight(left...)
{
static if (is(typeof(Template!(left, args))))
enum ApplyRight = Template!(left, args); // values
else
alias ApplyRight = Template!(left, args); // symbols
}
}
else
alias ApplyRight = Template;
alias ApplyRight(left...) = Template!(left, args);
}

///
Expand Down Expand Up @@ -1204,6 +1182,34 @@ unittest
typeof(&foo), typeof(&bar)) == SafeFunctions));
}

unittest // values
{
enum Templ1(int x) = x;
alias Partial1 = ApplyLeft!(Templ1, 1);
static assert(Partial1!() == 1);

enum Templ2(int x) = x;
alias Partial2 = ApplyLeft!Templ2;
static assert(Partial2!2 == 2);

enum Templ3(int a, double b, string c) = AliasSeq!(a, b, c);
alias Partial3 = ApplyLeft!(Templ3, 3, 3.3);
static assert(Partial3!"3" == AliasSeq!(3, 3.3, "3"));
}

unittest // issue 16070
{
alias Templ(T, string name) = AliasSeq!(T, name);
alias PartialL = ApplyLeft!(Templ, int);
alias FullL = PartialL!"foo";
static assert(is(FullL[0] == int));
static assert(FullL[1] == "foo");
alias PartialR = ApplyRight!(Templ, "bar");
alias FullR = PartialR!int;
static assert(is(FullR[0] == int));
static assert(FullR[1] == "bar");
}

/**
* Creates an `AliasSeq` which repeats a type or an `AliasSeq` exactly `n` times.
*/
Expand Down