What is the corect behavour for lazy in foreach variadic template

Artur Skawina via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Sep 25 09:38:25 PDT 2015


On 09/25/15 17:47, Ali Çehreli via Digitalmars-d-learn wrote:

> Perhaps we need an enhancement that either works in your original code [...]

His original code does work (`foreach` evaluates `args[N]` and
assigns the result to `arg`).

If he wanted to delay the evaluation, he would have written it
like this:

   void test(T...)(lazy T args)
   {
       foreach(I, _; typeof(args))
       {
           writeln("about to process arg");
           writefln("processing arg %s",args[I]);
       }
   }

artur


More information about the Digitalmars-d-learn mailing list