The std::is_member_function_pointer template of C++ STL is present in the <type_traits> header file. The std::is_member_function_pointer template of C++ STL is used to check whether the T is a pointer to non-static member function or not. It return the boolean value true if T is pointer to non-static member function, otherwise return false.
Header File:
#include<type_traits>
Template Class:
template <class T>
struct is_member_function_pointer;
Syntax:
std::is_member_function_pointer::value
Parameter: The template std::is_member_function_pointer accepts a single parameter T(Trait class) to check whether T is pointer to non-static member function or not.
Return Value: This template std::is_member_object_pointer returns a boolean variable as shown below:
- True: If the type T is a pointer to non-static member function type.
- False: If the type T is not a pointer to non-static member function type.
Below is the program to demonstrate std::is_member_function_pointer in C++:
Program 1:
#include <bits/stdc++.h>
#include <type_traits>
using namespace std;
class GFG {
public :
int gfg;
};
class A {
};
int main()
{
int GFG::*pt = &GFG::gfg;
cout << boolalpha;
cout << "GFG*: "
<< is_member_function_pointer<GFG*>::value
<< endl;
cout << "int GFG::* "
<< is_member_function_pointer< int GFG::*>::value
<< endl;
cout << "int A::* "
<< is_member_function_pointer< int A::*>::value
<< endl;
cout << "int A::*() "
<< is_member_function_pointer< int (A::*)()>::value
<< endl;
return 0;
}
|
Output:
GFG*: false
int GFG::* false
int A::* false
int A::*() true
Program 2:
#include <bits/stdc++.h>
#include <type_traits>
using namespace std;
struct A {
void fn(){};
};
struct B {
int x;
};
int main()
{
void (A::*pt)() = &A::fn;
cout << boolalpha;
cout << "A*: "
<< is_member_function_pointer<A*>::value
<< endl;
cout << "void(A::*)(): "
<< is_member_function_pointer< void (A::*)()>::value
<< endl;
cout << "B*: "
<< is_member_function_pointer<B*>::value
<< endl;
cout << "void(B::*)(): "
<< is_member_function_pointer< void (B::*)()>::value
<< endl;
return 0;
}
|
Output:
A*: false
void(A::*)(): true
B*: false
void(B::*)(): true
Reference: http://www.cplusplus.com/reference/type_traits/is_member_function_pointer/