View mode: basic / threaded / horizontal-split · Log in · Help
November 14, 2012
taskPool.map using functions with more than one input
Is it possible to use taskPool.map with functions that take more than one input?

Consider the following code which uses map to convert a given value to its sum 
with another number:

      import std.algorithm, std.parallelism, std.range, std.stdio;

      real pairsum(real x, real y)
      {
            writeln("Calculating sum of ", x, " + ", y);
            return x + y;
      }

      void main()
      {
            real x = 3.0;
            auto y = iota(0.0, 1.0, 0.05);

            auto psums = map!(a => pairsum(x, a))(y);

            foreach(s; psums)
                  writeln(s);
      }

Simply replacing map! with taskPool.map! results in a compilation error due to 
the use of the a => notation.  But how else to tell it the function arguments 
that should _not_ be iterated over?  Or is taskPool.map! limited to 
single-argument functions?
Top | Discussion index | About this forum | D home