I have several overloaded functions like
int a(int) {} float a(float) {} int b(int) {} float b(float) {}
My goal is to wrap these functions in a functor object:
template <typename T> struct func_a { auto T operator()(T t) -> decltype(a(t)) {return a(t);} };
Is there a way to determine the structure of the template described above over any other template by taking an overloaded function as an argument? Something like that:
template <> struct create_functor { template <typename T> struct func { auto operator()() -> decltype(f(t)) {return f(t);} } };
Therefore, I can generate the structure at compile time, as in:
typedef create_functor<a>::func<int> func_a_int; typedef create_functor<a>::func<float> func_a_float; typedef create_functor<b>::func<int> func_a_int; typedef create_functor<b>::func<float> func_a_float;
c ++ c ++ 11 functor
user1447257
source share