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

ag0aep6g anonymous at example.com
Tue Jul 31 20:03:39 UTC 2018


On 07/31/2018 09:17 AM, Shachar Shemesh wrote:
> 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.

Looks like you can do it with a "lazy variadic function" [1], but it's 
not pretty:

----
alias Dg = string delegate() @nogc nothrow;

void myAssert(bool cond, Dg[1] msg_dg ...) @nogc nothrow
{
     import core.stdc.stdio;
     if (!cond)
     {
         string msg = msg_dg[0]();
         printf("%*s\n", msg.length, msg.ptr);
     }
}
----

[1] https://dlang.org/spec/function.html#lazy_variadic_functions


More information about the Digitalmars-d mailing list