From 3715470eab4ce192b74db4d49276d50b5e27a702 Mon Sep 17 00:00:00 2001 From: anonymous Date: Tue, 24 May 2016 20:48:45 +0200 Subject: [PATCH] fix issue 16070 - std.meta.{ApplyLeft,ApplyRight} fail with mixed type/value arguments --- std/meta.d | 54 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/std/meta.d b/std/meta.d index f13566381a8..50d9c2f2fee 100644 --- a/std/meta.d +++ b/std/meta.d @@ -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); } /// @@ -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. */