Assert

Walter Bright newshound1 at digitalmars.com
Sun Jul 1 13:19:56 PDT 2007


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



More information about the Digitalmars-d mailing list