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 (それ以外の場合)
(公開静的メンバ定数)

メンバ関数

operator bool
オブジェクトを bool に変換し、 value を返す
(公開メンバ関数)
operator()
(C++14)
value を返す
(公開メンバ関数)

メンバ型

定義
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)
型がポインタ型かどうかをチェックする
(クラステンプレート)
型が非静的メンバオブジェクトポインタかどうかをチェックする
(クラステンプレート)
型が非静的メンバ関数ポインタかどうかをチェックする
(クラステンプレート)