How to append range to array?
Vladimir Panteleev via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat May 23 00:03:33 PDT 2015
int[] arr = [1, 2, 3];
auto r = iota(4, 10);
// ???
assert(equal(arr, iota(1, 10)));
Hopefully in one GC allocation (assuming we know the range's
length).
I tried std.range.primitives.put but its behavior seems a little
mysterious:
This compiles but asserts at runtime:
int[] arr = [1, 2, 3];
arr.put(iota(4, 10));
And this is even weirder, can you guess what it will print?
int[] arr = [1, 2, 3];
arr.put(4);
writeln(arr);
More information about the Digitalmars-d-learn
mailing list