Amusing D facts: typesafe variadic arrays are lazy!

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Tue Oct 13 10:06:31 PDT 2009


Max Samukha wrote:
> On Tue, 13 Oct 2009 15:06:25 +0200, downs <default_357-line at yahoo.de>
> wrote:
> 
>> Did you know the following code compiles?
>>
>>> module test;
>>>
>>> import std.stdio;
>>>
>>> void Assert(bool cond, string delegate()[] dgs...) {
>>>   debug if (!cond) {
>>>     string str;
>>>     foreach (dg; dgs) str ~= dg();
>>>     throw new Exception(str);
>>>   }
>>> }
>>>
>>> void main() {
>>>   Assert(false, "O hai thar! ");
>>> }
>>
>> It's true! :)
> 
> Yes, it is documented. "Lazy Variadic Functions" on "Functions" page.

Awesome. I'll replace the use of lazy in enforce() with that.

Andrei



More information about the Digitalmars-d mailing list