I'm working on introspection technics and wanted to implement a trait to tell if a member-function is static or not.
After a bit of reading (so and cppreference) I understand that the type of a pointer to static member function is exactly the same as a the one of a pointer to free function with the same signature.
As a consequence I cannot:
- tell if a member function is
static; - retrieve the class from a pointer to
staticmember function; - tell if a class has a given
staticmember function (I saw this question but I'm not sure if it's the same goal and the answer relies onstd::experimentalthat I cannot use).
Is there really no way to do that? (I think that there isn't, at least for the two first dashes; for the third one, I'm less sure)
[EDIT] It will be clearer with some snippet:
struct S {
static int foo(int);
};
template <typename Fun>
Process(Fun fun) {
std::cout << PrettyTypePrinting<is_member_of_t<FunPtr>>::Disp() << '\n';
}
int main() {
// tell if the input is a static member function
std::cout << std::boolalpha << is_static_member_v<decltype(S::foo)> << '\n';
// tell if the input has a given static member function
std::cout << std::boolalpha << has_static_foo_v<S> << '\n';
// retrieve the class from a member function
Process(S::foo);
}
Expecting:
true
true
struct S
It's pseudo-code by I hope it makes the goal clearer.
Besides, If there is a way to do that, I'd like to see the different solution for the different langage standard, starting with C++14.
Thanks
Tand a pointer to one of its member functions, can you tell whether the member function is static or not?" ?