The problem I'm facing is straightforward. Given the following code:
template <typename ReturnType, typename... Args>
auto CallIt( ReturnType( *method )( Args... ) )
{
return method;
}
auto test = CallIt( [] ( int a, int b )
{
return a > b;
} );
The error that I get (using VS13 with the November 2013 CTP compiler) is:
Could not deduce template argument for ReturnType (__cdecl *)(Args...) from main::<lambda_e795bf5a030334e5fc8f3c26dbe00e0e>
I understand that a lambda is not a function pointer, but a lambda that does not capture can be assigned to a function pointer of a matching signature. If you explicitly specify the template arguments, this works. I would love to see a way where this can work without having to explicitly specify the template arguments. Thank you in advance for your help.
As noted in the comments for the answer provided by Marco A., there may be a solution to this using the unary + operator on the lambda class, effectively casting it to a function pointer. However, in the requested IDE/compiler combination I receive the following warning-turned-error:
more than one conversion function from "lambda []bool (int a, int b)->bool" to a built-in type applies:
function "lambda []bool (int a, int b)->bool::operator bool (*)(int a, int b)() const"
function "lambda []bool (int a, int b)->bool::operator bool (*)(int a, int b)() const"
function "lambda []bool (int a, int b)->bool::operator bool (*)(int a, int b)() const"
function "lambda []bool (int a, int b)->bool::operator bool (*)(int a, int b)() const"
This intellisense error sheds light on the compile error generated specifying:
error C2593: 'operator +' is ambiguous