Is there a way to determine a return type of a member function pointer?
法典样本:
///// my library
void my_func(auto mptr) { // have to use `auto`
// some logic based on a return type of mptr: int, string, A, etc.
}
///// client code
struct A {
int foo();
std::string bar(int);
};
class B{
public:
A func(int, double);
};
// ... and many other classes
my_func(&A::foo);
my_func(&A::bar);
my_func(&B::func);
// ... many other calls of my_func()
我需要“填入”<代码>my_func()。
Edit:
I can t use std::result_of
/std::invoke_result
as I don t know the full list of parameters of mptr
. It s not important with which params a method is supposed to be called as I m not calling it. I would like to avoid creating an object of base class of mptr
even if I m able to determine it (using declval
is ok).