isForwardRange failed to recognise valid forward range

ketmar via Digitalmars-d digitalmars-d at puremagic.com
Mon May 4 03:25:23 PDT 2015


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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20150504/3a245bfd/attachment.sig>


More information about the Digitalmars-d mailing list