wrong isInputRange design
rumbu via Digitalmars-d
digitalmars-d at puremagic.com
Sun Dec 4 03:18:56 PST 2016
On Sunday, 4 December 2016 at 05:31:59 UTC, lobo wrote:
>
> This works for me when specialising for input ranges, strings
> and arrays.
>
> auto f(T)(T val)
> if(isInputRange!T && !isSomeString!T && !isArray!T) {}
>
> auto f(T)(T val)
> if(isSomeString!T) {}
>
> auto f(T)(T val)
> if(isArray!T && !isSomeString!T)
>
> bye,
> lobo
Yes, this is the same workaround I found, but that does not solve
the fact that the following code does not compile:
import std.range.primitives : isInputRange;
void f(T)(T val) if (isInputRange!T)
{
while (!val.empty) { auto c = val.front; val.popFront(); }
}
string s = "some string";
f(s);
Of course, the previous code will compile if we change the
imports:
import std.range.primitives: isInputRange, front, popFront, empty;
But that just prove the bad design of isInputRange which cannot
be used all alone without the rest of array UFCSs imported.
More information about the Digitalmars-d
mailing list