I would like to have a function, that calls a given member function with the provides variadic input argument. I wrote something like this:
#include <type_traits>
#include <utility>
struct A {
constexpr int show(int a, int b) const noexcept {return a + b;}
};
template <typename T, typename MemFn, typename ... Args>
int show(T && obj, MemFn Fn, Args&&... args)
{
return (obj.*Fn)(std::forward<Args>(args)...);
}
int main()
{
constexpr A a;
return show(a, &A::show, 1, 2);
}
and it works just fine, as long as I only have one definition of show method in my struct. As soon as I add something like
struct A {
constexpr int show(int a, int b) const noexcept {return a + b;}
constexpr int show(int a) const noexcept {return a * 3;}
};
The compiler can not deduce the type of the member function and it really makes all the sense, but I was wondering if there is a workaround for this problem, like embedding the input arguments types in member function template or something?
Sample code can be found here.