std.array.array seems to return flatten copy of input
anonymous
anonymous at example.com
Fri Apr 4 13:29:27 PDT 2014
On Friday, 4 April 2014 at 20:19:53 UTC, Olivier Grant wrote:
> import std.stdio;
> import std.range;
> import std.array;
>
> auto splice( size_t N, R )( R range )
> if(isInputRange!R)
> {
> struct Splicer
> {
> R array;
>
> @property bool empty( ) const
> { return 0 == array.length; }
>
> @property auto front( ) const
> { return array[0 .. N]; }
>
> void popFront( )
> { array = array[N .. $]; }
> }
>
> static assert(isInputRange!Splicer);
>
> assert(range.length % N == 0);
>
> Splicer res = { range };
> return res;
> }
>
> unittest
> {
> assert(equal([1,2,3,4].splice!(2), [[1,2],[3,4]]));
> }
>
> void main( )
> {
> auto a = [1,2,3,4];
>
> writeln(a.splice!(2));
> writeln(a.splice!(2).array);
> }
>
> which weirdly enough gives me the following output :
>
> [[1,2],[3,4]] // I expect that.
> [1,2,3,4] // But what is happening here ?
a.splice!(2).array is the field of the Splicer struct. Rename
that or call std.array.array not via UFCS.
More information about the Digitalmars-d-learn
mailing list