Cannot alias expression

simendsjo simendsjo at gmail.com
Mon Oct 21 12:14:23 PDT 2013


On Monday, 21 October 2013 at 18:42:27 UTC, John Colvin wrote:
> On Monday, 21 October 2013 at 12:58:55 UTC, John Colvin wrote:
>> I suspect I'm being very dumb here, but I can't get my head 
>> around this:
>>
>>    template B(alias A)
>>    {
>> 	alias B = A;
>>    }
>>    template C(A ...)
>>    {
>> 	alias C = A[0];
>>    }
>>    static assert(B!1 == 1); //fine
>>    static assert(C!1 == 1); //Error: cannot alias an 
>> expression 1
>
> Also:
>
>     struct S{}
>
>     template B(alias A)
>     {
>         alias B = A;
>     }
>     template C(A ...)
>     {
>         alias C = A[0];
>     }
>     pragma(msg, B!int); //Error: template instance B!(int)
>           //does not match template declaration B(alias A)

Alias doesn't take primitive types. I usually add a regular B(A) 
template overload too. Note that when you have a alias A 
overload, structs uses that rather than the basic A template.

>     pragma(msg, B!S); // S
>     pragma(msg, C!int); // int
>     pragma(msg, C!S); // S



More information about the Digitalmars-d-learn mailing list