How is it possible to access the types of the parameters of a lambda function in c++? The following does not work:
template <class T> struct capture_lambda {
};
template <class R, class T> struct capture_lambda<R(T)> {
static void exec() {
}
};
template <class T> void test(T t) {
capture_lambda<T>::exec();
}
int main() {
test([](int i)->int{ return 0; });
}
The above does not compile, because the compiler chooses the template prototype instead of the specialization.
Is there a way to do the above?
What I am actually trying to achieve is this: I have a list of functions and I want to select the appropriate function to invoke. Example:
template <class T, class ...F> void exec(T t, F... f...) {
//select the appropriate function from 'F' to invoke, based on match with T.
}
For example, I want to invoke the function that takes 'int':
exec(1, [](char c){ printf("Error"); }, [](int i){ printf("Ok"); });