On Monday, 24 October 2016 at 14:25:46 UTC, Dorian Haglund wrote:
Hey,
The following code crashes with DMD64 D Compiler v2.071.2:
import std.algorithm;
import std.stdio;
import std.range;
int main()
{
repeat(8, 10).chunks(3).writeln();
return 0;
}
Error message:
pure nothrow @nogc @safe
std.range.Take!(std.range.Repeat!(int).Repeat).Take
std.range.Repeat!(int).Repeat.opSlice(ulong, ulong)
If I replace repeat with iota, or a literal range (like [1, 2
,3, 4]), I don't get the crash.
I don't see why I should not be able to use chunks with repeat.
If some property of repeat's range is missing to use chunks,
shouldn't I get an error message ?
Am I missing something ?
PS: the behavior has been reproduced on someone else computer.
Cheers :)
This works:
repeat(8, 12).chunks(3).writeln;
The documentation of
https://dlang.org/phobos/std_range.html#.chunks mentions
something about evenly divisible by chunkSize – perhaps that is
the cause of the assert fail. Not 100% sure why that's there
though.
Thanks,
Saurabh