Assert

Lutger lutger.blijdestijn at gmail.com
Sat Jun 30 04:57:28 PDT 2007


David B. Held wrote:
> Sean Kelly wrote:
>> [...]
>> Seems like the main problem is that assert is compiled out in release 
>> builds, correct?  Throwing a custom message and such already works.
> 
> No, you guys are missing the important point: *stringizing the 
> condition*.  That is what is impossible without repeating the condition 
> or having macros.
> 
> Dave


Not impossible, but ugly:


char[] enforce(char[] cond, char[] msg)
{
     return "if (!(" ~ cond ~ "))
             throw new Exception(\"" ~ cond ~ ": " ~ msg ~ "\");";
}


mixin(enforce("ptr != null", "foo() failed"));




More information about the Digitalmars-d mailing list