Possible issue with isInputRange

Maor Ben Dayan via Digitalmars-d digitalmars-d at puremagic.com
Wed Sep 23 16:10:20 PDT 2015


isInputRange will always return true for a range returning ref to 
non-copyable type.
This is a problem when trying to work with chain etc. together 
with such ranges.
The problem is that the test in isInputRange should have been 
similar to A below instead of B (no need to try and assign the 
return value of front for the range to be an input range).
Below is a reduced code example.

Am I correct in assuming that this is a phobos bug ?

code example:

void main()
{
     import std.range;
     import std.traits;

     struct Snowflake {
         int x;
         @disable this(this);
     }

     Snowflake[12] flakes;
     foreach(uint i; 0..flakes.length) {
         flakes[i].x = i;
     }
     alias R = Snowflake[];

     foreach(ref s; flakes[0..$]) { /* works just fine, I guess it 
is a valid input range */
         // do something
     }

     static assert(is(typeof((inout int = 0) { R r = R.init; })));
     static assert(is(typeof((inout int = 0) { R r = R.init; if 
(r.empty) {} })));
     static assert(is(typeof((inout int = 0) { R r = R.init; 
r.popFront(); })));
     static assert(is(typeof((inout int = 0) { R r = R.init; 
r.front; })));        /* A passes */
     static assert(is(typeof((inout int = 0) { R r = R.init; h = 
r.front; })));  /* B fails */
     static assert(isInputRange!(Snowflake[]));                    
               /* fails */
}


More information about the Digitalmars-d mailing list