From Lambda function passed as parameter I can compile the example:
template <class Range>
Range FindFirstIf(Range, bool(*Function)(typename Range::ConstReference value));
struct range { using ConstReference = const float&; };
range rng;
rng = FindFirstIf(rng, [](const float& val) { return (val < 0.0f); });
Of course it can't link as FindFirstIf
is not implemented.
However, when I did a similar thing:
template <class Range, class ValueType>
Range MyTest(Range, ValueType, bool(*Function)(ValueType value));
std::vector <int> vi;
double d = 0;
vi = MyTest(vi, d, [](double val) { return (val < 0.0f); });
It has compilation error:
error C2784: 'Range MyTest(Range,ValueType,bool (__cdecl *)(ValueType))' : could not deduce template argument for 'bool (__cdecl *)(ValueType)' from 'main::'
why so? I thought by passing d
in, ValueType
can be deduced as double
?