Thanks for your explications!

On Friday, 19 May 2023 at 21:18:28 UTC, Ali Çehreli wrote:
[...]
- std.range.zip can be used instead but it does not provide 'ref' access to its elements.

How/why does sort [1] work with zipped arrays?

[...]

The following amap example there may be useful for your case but I could not make the types work:

Do you mean using the function pointer does not work?

// Same thing, but explicitly allocate an array
// to return the results in.  The element type
// of the array may be either the exact type
// returned by functions or an implicit conversion
// target.
auto squareRoots = new float[numbers.length];
taskPool.amap!sqrt(numbers, squareRoots);

This even seems to work with a static function pointer:

   int main ()
   {
      import std.stdio;
      import std.math;
      import std.parallelism;

      const double [] a = [1., 2., 3., 4.];
      double [] b = [0., 0., 0., 0.];

      writeln (a);
      writeln (b);

      double function (double) fp = &sqrt;
      taskPool.amap!fp (a, b);

      writeln (a);
      writeln (b);
      return 0;
   }

Using an automatic variable gives a deprecation warning

   main.amap!(const(double)[], double[]).amap` function requires a
   dual-context, which is deprecated

[1] https://dlang.org/library/std/range/zip.html

Reply via email to