link-time codegen assert?

Tove tove at fransson.se
Tue Oct 1 04:42:19 PDT 2013


A very minimal example:

template ctfe(alias any)
{
   alias ctfe = any;
}

double ms(double val) pure nothrow @property
{
   if(__ctfe)
     return val / 1000.0;
   else
     assert(false);
}

The above allows for writing...
   ctfe!(10.ms)
... which is in natural reading order as opposed to...
   ms!10
... but one would have to guard against users accidentally 
writing...
   10.ms
... which would be a catastrophic hidden performance bug.

I was not able to find a way to use static assert only when there 
is code-generated for the function, so my question is. Do you see 
a generic need for a 3rd type of assert or can you find a way to 
solve the above issue in another way?


More information about the Digitalmars-d mailing list