Frequent cannot deduce function from argument types

Edwin van Leeuwen via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Oct 16 08:48:57 PDT 2015


Just wondering if anyone has any tips on how to solve/avoid 
"cannot deduce function from argument types" when relying on 
template programming.

I run into these problems all the time. Current one was when I 
tried:

```
auto ys = NumericLabel(groupedAes.front.map!((t)=>t.y));
```

NumericLabel is a pretty minimal templated InputRange, with as 
only requirement on the argument that it is also an InputRange. I 
then get the following compile error:

```
source/ggplotd/geom.d(83,35): Error: struct 
ggplotd.aes.NumericLabel cannot ded
uce function from argument types !()(MapResult!(__lambda2, 
FilterResult!(__lamb
da2, Aes!(double[], "x", double[], "y", string[], "colour")))), 
candidates are:
source/ggplotd/aes.d(515,1):        ggplotd.aes.NumericLabel(T) 
if (isInputRang
e!T)
```

As far as I know MapResult always returns an input range and as 
you can see there is only one candidate of NumericLabel, so to be 
honest it looks relatively straightforward to me.

Now I can define the type specifically (and/or typeof) but it 
seems like there should be a better way.

In this case typeof isn't even happy:
```
source/ggplotd/geom.d(84,17): Error: constructor 
ggplotd.aes.NumericLabel!(MapResult!(__lambda2, 
FilterResult!(__lambda2, Aes!(string[], "x", string[], "y", 
string[], "colour")))).NumericLabel.this (MapResult!(__lambda2, 
FilterResult!(__lambda2, Aes!(string[], "x", string[], "y", 
string[], "colour"))) range) is not callable using argument types 
(MapResult!(__lambda3, FilterResult!(__lambda2, Aes!(string[], 
"x", string[], "y", string[], "colour"))))
```

If we look closely, it expects a __lambda2 as the MapResult 
argument, but it gets a __lambda3.


I am able to work around it by converting the mapresult to an 
array, but I'd rather use a lazy solution.






More information about the Digitalmars-d-learn mailing list