std::is_member_pointer in C++ with Examples

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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;
}

chevron_right


Output:

GFG::* is a Member Pointer!
int is not a Member Pointer!

Reference: http://www.cplusplus.com/reference/type_traits/is_member_pointer/

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.