Parallel foreach over AliasSec?

ag0aep6g via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Feb 26 18:02:57 PST 2017


On 02/27/2017 01:35 AM, Bastiaan Veelo wrote:
> template eval_all(funcs...)
> {
>     void eval_all(int val)
>     {
>         import std.parallelism;
>         //foreach (i, f; parallel(funcs))    // Tries to evaluate f(void)
>         foreach (i, f; funcs)    // How do I parallelise this?
>             values[i] = f(val);
>     }
> }

Make a range or an array of function pointers from the AliasSeq of 
function aliases:

----
import std.meta: staticMap;
import std.range: only;

enum fptr(alias f) = &f;
enum fptrs = staticMap!(fptr, funcs);
auto r = only(fptrs);

foreach (i, f; parallel(r))
     values[i] = f(val);
----



More information about the Digitalmars-d-learn mailing list