Assert
Don Clugston
dac at nospam.com.au
Sat Jun 30 12:48:02 PDT 2007
David B. Held wrote:
> Lutger wrote:
>> [...]
>> Not impossible, but ugly:
>>
>> char[] enforce(char[] cond, char[] msg)
>> {
>> return "if (!(" ~ cond ~ "))
>> throw new Exception(\"" ~ cond ~ ": " ~ msg ~ "\");";
>> }
>>
>> mixin(enforce("ptr != null", "foo() failed"));
>
> Well, "stringizing by hand" isn't exactly in the repertoire of
> possibility that I was considering, given that we can write any code we
> want in a mixin statement. Clearly, this kind of solution is less than
> ideal.
Yes, but it's really only syntactic sugar that's lacking. The functionality is
almost identical to what you'd want from a macro. We're _so_ close.
>
> Dave
More information about the Digitalmars-d
mailing list