How std.range.ElementType should be used in template constraints?
I assumed this way, but I was wrong
import std.range;
auto f(T)(T x)
if (ElementType!(T) is uint) // adding this line causes lot of error messages
// first of which is: found ')' when expecting '.' following uint
{
return x;
}
f(map!"a"([1,2,3,4]));
The is expression is not the same as the is operator. Documentation on the is expression is here: http://dlang.org/expression.html#IsExpression. The is operator does a bitwise comparison of values whereas the is expression compares types (and does crazy pattern matching). Your constraint should be written like this:
Or, if you want to match anything implicitly convertible to a uint as well:
Further, I’ve fixed your invocations of ElementType, adding the “!” where appropriate; ElementType is a template, not a function.