Namespaces
Variants

std:: is_member_pointer

From cppreference.net
Metaprogramming library
Type traits
Type categories
(C++11)
(C++11) ( DR* )
is_member_pointer
(C++11)
Type properties
(C++11)
(C++11)
(C++14)
(C++11) (deprecated in C++26)
(C++11) ( until C++20* )
(C++11) (deprecated in C++20)
(C++11)
Type trait constants
Metafunctions
(C++17)
Supported operations
Relationships and property queries
Type modifications
Type transformations
(C++11) (deprecated in C++23)
(C++11) (deprecated in C++23)
(C++11)
(C++11) ( until C++20* ) (C++17)

Compile-time rational arithmetic
Compile-time integer sequences
헤더에 정의됨 <type_traits>
template < class T >
struct is_member_pointer ;
(C++11부터)

std::is_member_pointer UnaryTypeTrait 입니다.

만약 T 가 비정적 멤버 객체에 대한 포인터이거나 비정적 멤버 함수에 대한 포인터인 경우, 멤버 상수 value true 로 제공합니다. 다른 모든 타입에 대해서는 value false 입니다.

프로그램이 std::is_member_pointer 또는 std::is_member_pointer_v 에 대한 특수화를 추가하는 경우, 그 동작은 정의되지 않습니다.

목차

템플릿 매개변수

T - 확인할 타입

헬퍼 변수 템플릿

template < class T >
constexpr bool is_member_pointer_v = is_member_pointer < T > :: value ;
(C++17부터)

std:: integral_constant 로부터 상속됨

멤버 상수

value
[static]
true 만약 T 가 멤버 포인터 타입이면, false 그렇지 않으면
(public static member constant)

멤버 함수

operator bool
객체를 bool 로 변환, value 반환
(public member function)
operator()
(C++14)
value 반환
(public member function)

멤버 타입

타입 정의
value_type bool
type std:: integral_constant < bool , value >

가능한 구현

template<class T>
struct is_member_pointer_helper : std::false_type {};
template<class T, class U>
struct is_member_pointer_helper<T U::*> : std::true_type {};
template<class T>
struct is_member_pointer : is_member_pointer_helper<typename std::remove_cv<T>::type> {};

예제

#include <cassert>
#include <type_traits>
static_assert(!std::is_member_pointer_v<int*>);
struct S
{
    int i{42};
    int foo() { return 0xF00; }
};
using mem_int_ptr_t = int S::*;
using mem_fun_ptr_t = int (S::*)();
static_assert(std::is_member_pointer_v<mem_int_ptr_t>);
static_assert(std::is_member_pointer_v<mem_fun_ptr_t>);
int main()
{
    S s;
    mem_int_ptr_t pm = &S::i;
    assert(s.i == s.*pm);
    mem_fun_ptr_t pmf = &S::foo;
    assert((s.*pmf)() == s.foo());
}

참고 항목

(C++11)
타입이 포인터 타입인지 검사합니다
(클래스 템플릿)
타입이 비정적 멤버 객체 포인터인지 검사합니다
(클래스 템플릿)
타입이 비정적 멤버 함수 포인터인지 검사합니다
(클래스 템플릿)