isInputRange copied verbatim produces a different result than isInputRange from std.range

aliak something at something.com
Sun Mar 4 12:57:41 UTC 2018


Hi, I have a custom type D with front/popFront/empty implemented 
as free functions, but isInputRange returns false. I copied the 
implementation of isInputRange, and that custom implementation 
returns true... anyone know what's going on here?

===
import std.stdio, std.range, std.traits;

// Code copied veratim from:
// 
https://github.com/dlang/phobos/blob/v2.079.0/std/range/primitives.d#L164
enum bool isIR(R) =
     is(typeof(R.init) == R)
     && is(ReturnType!((R r) => r.empty) == bool)
     && is(typeof((return ref R r) => r.front))
     && !is(ReturnType!((R r) => r.front) == void)
     && is(typeof((R r) => r.popFront));

struct D {}

@property int front(D d) { return 2; }
@property bool empty(D d) { return false; }
void popFront(D d) {}

pragma(msg, isIR!D); // true
pragma(msg, isInputRange!D); // false ???

pragma(msg, is(typeof(D.init) == D)); // true
pragma(msg, is(ReturnType!((D r) => r.empty) == bool)); // true
pragma(msg, is(typeof((return ref D r) => r.front))); // true
pragma(msg, !is(ReturnType!((D r) => r.front) == void)); // true
pragma(msg, is(typeof((D r) => r.popFront))); // true

void main() {}
===

Thanks for any help!
- Ali


More information about the Digitalmars-d-learn mailing list