On Wednesday, 29 April 2020 at 08:34:53 UTC, Ogi wrote:
struct R {}
int front(R r) { return 42; }
void popFront(R r) {}
bool empty(R r) { return false; }

void main() {
    import std.range.primitives : isInputRange;
    static assert(isInputRange!R);
}

Error: static assert:  `isInputRange!(R)` is false

Whats really weird is that if I replace isInputRange with its definition from std.range.primitives, it returns true:

import std;

struct R {}
int front(R r) { return 42; }
void popFront(R r) {}
bool empty(R r) { return false; }

void main() {
    static assert(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)));
}
This compiles.

What’s going on here?

The static checker doesn't see your free funcs because to do so it would have to import the whole module. (is it possible to do that ? no idea.) Also your signature for the primitives are quite unusual (i.e not idiomatic). Usually they dont take param. Usually we pass a type that contains the member funcs matching to IsIntputRange.

Reply via email to