The std::is_member_pointer template of C++ STL is present in the <type_traits> header file. The std::is_member_pointer template of C++ STL is used to check whether the T is a pointer to non-static member or not. It return the boolean value true if T is a pointer to non-static member type, Otherwise return false.
Header File:
#include<type_traits>
Template Class:
template<class T> struct is_member_pointer : std::integral_constant < bool, is_member_object_pointer<T>::value || is_member_function_pointer<T>::value> {};
Syntax:
std::is_member_pointer::value
Parameters: The template std::is_member_pointer accepts a single parameter T(Trait class) to check whether T is pointer to non-static member or not.
Return Value: This template returns a boolean variable as shown below:
- True: If the type T is pointer to non-static member.
- False: If the type T is not a pointer to non-static member.
Below is the program to illustrates the std::is_member_pointer template in C/C++:
Program:
// C++ program to illustrate // std::is_member_pointer #include <bits/stdc++.h> #include <type_traits> using namespace std;
// Driver Code int main()
{ // Empty Class GFG
class GFG {
};
// Check if GFG::* is a member
// pointer or not
bool a = is_member_pointer< int (GFG::*)>::value;
if (a) {
cout << "GFG::* is a Member Pointer!"
<< endl;
}
else {
cout << "GFG::* is not a Member Pointer!"
<< endl;
}
// Check if int is a member
// pointer or not
a = is_member_pointer< int ( int )>::value;
if (a) {
cout << "int is a Member Pointer!"
<< endl;
}
else {
cout << "int is not a Member Pointer!"
<< endl;
}
return 0;
} |
GFG::* is a Member Pointer! int is not a Member Pointer!
Reference: http://www.cplusplus.com/reference/type_traits/is_member_pointer/