Is there any hope for "lazy" and @nogc?

Shachar Shemesh shachar at weka.io
Tue Jul 31 07:17:34 UTC 2018


I'm trying to figure out what's the signature of the built-in assert. It 
does not seem that I can define a similar function myself.

First attempt:
void myAssert(bool cond, string msg) @nogc nothrow;

No, because msg gets evaluated unconditionally.

void myAssert(bool cond, lazy string msg) @nogc nothrow;

test.d(8): Error: @nogc function test.myAssert cannot call non- at nogc 
delegate msg

void myAssert(bool cond, lazy string msg @nogc nothrow ) @nogc nothrow;

test.d(4): Error: found @ when expecting )
test.d(4): Error: semicolon expected following function declaration
test.d(4): Error: no identifier for declarator nogc
test.d(4): Error: declaration expected, not )
test.d(9): Error: unrecognized declaration

Templates to the rescue!!!
void myAssert(STR)(bool cond, lazy STR msg );

test.d(14): Error: @nogc function D main cannot call non- at nogc function 
test.myAssert!string.myAssert

Help??

Shachar


More information about the Digitalmars-d mailing list