What is the corect behavour for lazy in foreach variadic template

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Sep 25 16:07:57 PDT 2015


On 09/25/2015 09:38 AM, Artur Skawina via Digitalmars-d-learn wrote:
> 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
>

Awesome! :)

Ali



More information about the Digitalmars-d-learn mailing list