isForwardRange failed to recognise valid forward range

Alex Parrill via Digitalmars-d digitalmars-d at puremagic.com
Mon May 4 07:33:11 PDT 2015


On Monday, 4 May 2015 at 10:25:23 UTC, ketmar wrote:
> here is some code for your amusement:
>
> struct Input {
>   auto opSlice (size_t start, size_t end) {
>     static struct InputSlice {
>       @property bool empty () { return false; }
>       @property char front () { return 0; }
>       void popFront () {}
>       InputSlice save () { return this; }
>     }
>     import std.range.primitives;
>     static assert(isForwardRange!InputSlice);
>     return InputSlice();
>   }
> }
>
> fixing code like this tames `isForwardRange`:
>
> template isForwardRange(R)
> {
>     enum bool isForwardRange = isInputRange!R && is(typeof(
>     (inout int = 0)
>     {
>         R r1 = R.init;
>         //old: static assert (is(typeof(r1.save) == R));
>         auto s1 = r1.save;
>         static assert (is(typeof(s1) == R));
>     }));
> }
>
> i wonder if some other checking primitives has similar bug.

Add @property to save.


More information about the Digitalmars-d mailing list