Get template parameter value

John Colvin via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Sep 29 03:03:44 PDT 2015


On Tuesday, 29 September 2015 at 09:53:39 UTC, Kagamin wrote:
> On Tuesday, 29 September 2015 at 09:11:15 UTC, John Colvin 
> wrote:
>> Welcome to the weird and wonderful work of  
>> http://dlang.org/expression.html#IsExpression
>
> No, use template pattern matching instead:
>
> struct A(int s){}
> template B(T:A!s, int s){ enum B=s; }
> static assert(B!(A!4)==4);

For some reason I never think of template pattern matching. Not 
my favourite feature, although it's probably just the ':' that 
bothers me, I always think of implicit convertibility like in 
is(T : Q). Anyway, you're right, it makes for shorter, neater 
code in simple cases (the static if version is equivalent if you 
just add a template constraint to it).


More information about the Digitalmars-d-learn mailing list