I have the following code I try to build with c++11 on XCode 5.1:
template<class T>
float calc2(std::function<float(T)> f) { return -1.0f * f(3.3f) + 666.0f; }
int main(int argc, const char* argv[])
{
calc2([](float arg) -> float{ return arg * 0.5f; }); //(1) - Will not compile - no matching function...
calc2<float>([](float arg) -> float{ return arg * 0.5f; }); // (2) - Compiles well
return 0;
}
Can someone explain why (1) does not compile? Shouldn't the compiler deduce T from the lambda definition?
Thanks!