ted:

Could someone enlighten me ?

This works:


import std.range: ElementType, isInputRange;

ElementType!R testFunc(R, T)(R range, T foo)
if (is(ElementType!R == T)) {
   static assert(isInputRange!R);
   typeof(return) retVal = foo ^^ 2; // More DRY.
   return retVal;
}

void main() {
   auto values = [0.0, 3.0, -1.0, 5.0];
   auto result = testFunc(values, 8.8);
}


The D compiler seems unable to compute ElementType!R in the function signature. If I am right, then this seems worth an enhancement request.

Bye,
bearophile

Reply via email to