I have written a templated function which is designed to accept a lambda and a pack of arguments. I have declared the return type of my function to be the return type of the lambda. Is there a way I can specialize my templated function for certain lambda parameter return types?
The working portion of my code is as follows:
template <typename F, typename ... T>
auto crudeProfile(F f, T ... args) -> decltype(f(args...)) {...}
This works as I would expect it to. But I’d like to specialize its behavior on lambdas that return void. I have only so far come up with the following code:
template <typename F, typename ... T>
void crudeProfile(F f, T ... args) {...}
But the compiler complains about this when I try to use it:
1>Source.cpp(684): error C2668: 'crudeProfile': ambiguous call to overloaded function
1> Source.cpp(637): note: could be 'void crudeProfile<main::<lambda_a7118596c99e3162db30942634c4e81e>,>(F)'
1> with
1> [
1> F=main::<lambda_a7118596c99e3162db30942634c4e81e>
1> ]
1> Source.cpp(624): note: or 'void crudeProfile<main::<lambda_a7118596c99e3162db30942634c4e81e>,>(F)'
1> with
1> [
1> F=main::<lambda_a7118596c99e3162db30942634c4e81e>
1> ]
1> Source.cpp(684): note: while trying to match the argument list '(main::<lambda_a7118596c99e3162db30942634c4e81e>)'
Even lambdas that return non-void result in this error, though the error will slightly change, to read "could be 'type' or void" (where 'type' is whatever the lambda return type is).