Assert
David B. Held
dheld at codelogicconsulting.com
Sun Jul 1 13:29:38 PDT 2007
Walter Bright wrote:
> David B. Held wrote:
>> Obviously there's a thousand ways to riff on that basic idea, but try
>> writing this function in D. As you can see, it's essentially a form
>> of assert().
>
> Done:
>
> T Enforce(T)(T p, lazy char[] msg)
> {
> if (!p)
> throw new Exception(msg());
> return p;
> }
>
> http://www.digitalmars.com/d/1.0/lazy-evaluation.html
Yeah, that's what everyone else said. But what it is missing is
*stringizing of the condition*, so that you can put it into the message.
For Enforce(), that's not as important; but for a custom assert(), it is.
Dave
More information about the Digitalmars-d
mailing list