Let's consider a kind of "invoke" function (here named "call") that helps to call a member function passed by a template argument. In this function, I would need to know the type of the class that owns the member function. Is there a way (in c++14 preferably) to do so ?
#include <functional>
template<typename F, typename... Args, std::enable_if_t<std::is_member_pointer<std::decay_t<F>>{}, int> = 0 >
constexpr decltype(auto) call(F&& f, Args&&... args) noexcept(noexcept(std::mem_fn(f)(std::forward<Args>(args)...)))
{
// Here we know that f is a member function, so it is of form : &some_class::some_function
// Is there a way here to infer the type some_class from f ? For exemple to instantiate a variable from it :
// imaginary c++ : class_of(f) var;
return std::mem_fn(f)(std::forward<Args>(args)...);
}
int main()
{
struct Foo { void bar() {} } foo;
call(&Foo::bar, &foo /*, args*/);
return 0;
}