Weird issue with std.range.iota.length

Meta via Digitalmars-d digitalmars-d at puremagic.com
Thu Feb 11 21:51:34 PST 2016


If you try to compile this code, it will currently not work:

foreach (n; iota(1UL, 1000).parallel)
{
     //...
}


This is because of how the length is calculated by iota:

auto iota(B, E)(B begin, E end)
if (isIntegral!(CommonType!(B, E)) || isPointer!(CommonType!(B, 
E)))
{
     import std.conv : unsigned;

     //...

     //The return type of length. When either begin or end
     //is ulong, then IndexType == ulong
     alias IndexType = typeof(unsigned(end - begin));

     static struct Result
     {
         private Value current, pastLast;

         //...

         @property IndexType length() const
         {
             return unsigned(pastLast - current);
         }
     }

     return Result(begin, end);
}


And because std.parallelism.TaskPool.defaultWorkUnitSize takes a 
size_t, which with a 32-bit DMD is uint.

What I want to know is, is this considered a bug? If so I will 
submit a pull request to fix it.


More information about the Digitalmars-d mailing list