On Wednesday, 25 November 2015 at 08:10:03 UTC, Jack Applegame
wrote:
This doesn't compile:
import std.range;
import std.algorithm;
void main() {
char[64] arr;
copy(chain("test1", "test2"), arr[0..10]);
}
http://dpaste.dzfl.pl/24230ac02e6e
Essentially this comes down to the question: 'Should output
ranges auto-encode like input ranges auto-decode'. The code above
suggests the answer is currently "no".
Workarounds:
Either do `dchar[64] arr;` or
import std.range;
import std.algorithm;
import std.utf;
void main() {
char[64] arr;
copy(chain("test1", "test2").byCodeUnit, arr[0..10].byCodeUnit);
}
ranges iterate over strings by code-point (i.e. dchar).
byCodeUnit forces iteration by code-unit i.e. char. You could
also do
import std.range;
import std.algorithm;
void main() {
char[64] arr;
copy(chain(cast(immutable(ubyte)[])"test1",
cast(immutable(ubyte)[])"test2"), cast(ubyte[])arr[0..10]);
}
or any other method that means you deal in ubyte[] instead of
char[].