digitalmars.D.learn - Is it a bug?
- Jack Applegame (8/8) Nov 25 2015 This doesn't compile:
- John Colvin (26/34) Nov 25 2015 Essentially this comes down to the question: 'Should output
- Jack Applegame (2/10) Nov 25 2015 I'll use byCodeUnit. Thanks.
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
Nov 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/24230ac02e6eEssentially 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[].
Nov 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.
Nov 25 2015