playing around with D
Don Clugston
dac at nospam.com.au
Mon Mar 5 23:17:23 PST 2007
Walter Bright wrote:
> Carsten Scharfenberg wrote:
[snip]
>> isTupleContainer checks, of course, if T is a TupleContainer. This
>> works fine in
>> the main function - but in AssertTest its result seems always to be true
>> so that the assert is never triggered.
>
> The problem is you are expecting that the static assert is checked
> before the alias in AssertTest. Multiple semantic passes are done over
> the declarations, and static assert's aren't checked until later. To
> ensure an order, use static if, such as:
>
> template AssertTest( T )
> {
> static if( isTupleContainer!( T ) )
> alias DoSomething!( T ).Result AssertTest;
> else
> static assert(0);
> }
This is becoming a genuine Frequently Asked Question (I think it's been
asked twice in the past week). Probably the spec should include some
explanation in the 'static assert' section -- eg
Note that multiple semantic passes are done over the declarations, and
static assert's are not checked until the template has already been
partially evaluated. To ensure an order, use static if.
--> plus an example.
More information about the Digitalmars-d
mailing list