How to work around the infamous dual-context when using delegates together with std.parallelism

Christian Köstlin christian.koestlin at gmail.com
Thu May 27 21:15:43 UTC 2021


On 2021-05-27 18:56, Ali Çehreli wrote:
> On 5/27/21 9:19 AM, Ali Çehreli wrote:
> 
>>    auto result = new string[users.length];
>>    users.enumerate.parallel.each!(en => result[en.index] = 
>> servers.doSomething(en.value));
>>    writeln(result);
> 
> I still like the foreach version more:
> 
>      auto result = new string[users.length];
>      foreach (i, user; users.parallel) {
>        result[i] = servers.doSomething(user);
>      }
>      writeln(result);
> 
> Ali
> 
Hi Ali,

both of those variants do work for me, thanks a lot!
Still not sure which I prefer (almost too many options now :) ).

I am so happy that I asked in this forum, help is much appreciated!

Christian


More information about the Digitalmars-d-learn mailing list