void foo(T)(InputRange!T range);

Update:

Ahh, it seems this syntax is currently accepted by DMD. Should it be?


Original function:

import std.range: isInputRange;

bool allEqual(R)(R range) @safe pure nothrow if (isInputRange!R)
{
    import std.algorithm: findAdjacent;
    import std.range: empty;
    return range.findAdjacent!("a != b").empty;
}
unittest { assert([11, 11].allEqual); }
unittest { assert(![11, 12].allEqual); }
unittest { int[] x; assert(x.allEqual); }

compiles.


New function:

import std.range: InputRange;

bool allEqual_(T)(InputRange!T range) @safe pure nothrow
{
    import std.algorithm: findAdjacent;
    import std.range: empty;
    return range.findAdjacent!("a != b").empty;
}
unittest { assert([11, 11].allEqual_); }
unittest { assert(![11, 12].allEqual_); }
unittest { int[] x; assert(x.allEqual_); }


fails as

algorithm_ex.d(190,27): Error: template algorithm_ex.allEqual_ cannot deduce function from argument types !()(int[]), candidates are: algorithm_ex.d(184,6): algorithm_ex.allEqual_(T)(InputRange!T range) algorithm_ex.d(191,28): Error: template algorithm_ex.allEqual_ cannot deduce function from argument types !()(int[]), candidates are: algorithm_ex.d(184,6): algorithm_ex.allEqual_(T)(InputRange!T range) algorithm_ex.d(192,29): Error: template algorithm_ex.allEqual_ cannot deduce function from argument types !()(int[]), candidates are: algorithm_ex.d(184,6): algorithm_ex.allEqual_(T)(InputRange!T range)

Reply via email to