I'm trying to use the slice operator to obtain a slice of the return value of the take function from std.range. My code:
auto tempChunk = ['a', 'b', 'c', 'd'];
auto a = tempChunk.take(3);
writeln(a[0..2]);
As Take!R in this case is just an alias for char[], I'd expect this to compile. However, the compiler tells me that Take!(char[]) cannot be sliced with []
. Taking another example:
int[] arr1 = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ];
auto s = arr.take(5);
writeln(s[0..4]);
This will compile and run without a problem, printing [1, 2, 3, 4, 5]. I am completely confused at this point as to why the first example won't work, while the second does.
writeln(a[0]);
, it doesn't work. What is the reason for this? – Fortieth