"cannot deduce function from argument types" issue.

ted via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Feb 10 01:13:12 PST 2015


bearophile wrote:

> 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

thanks !...

... where you say 'More DRY' above, are you referring to 
 - foo^^2 ( I just did foo*foo for the sake of the example), or
 - typeof(return) - a construct I am completely unfamiliar with and will 
now have to look up !

If it is 'typeof(return)' why would this be selected over ElementType!R ?? 
Is it more idiomatic ?


regards,
ted


More information about the Digitalmars-d-learn mailing list