Thread overview
Is it a bug?
Nov 25, 2015
Jack Applegame
Nov 25, 2015
John Colvin
Nov 25, 2015
Jack Applegame
November 25, 2015
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
November 25, 2015
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[].
November 25, 2015
On Wednesday, 25 November 2015 at 09:31:15 UTC, John Colvin wrote:
> import std.range;
> import std.algorithm;
> import std.utf;
>
> void main() {
> 	char[64] arr;
> 	copy(chain("test1", "test2").byCodeUnit, arr[0..10].byCodeUnit);
> }
I'll use byCodeUnit. Thanks.