Namespaces
Variants

std:: is_pointer

From cppreference.net
Metaprogramming library
Type traits
Type categories
(C++11)
(C++11) ( DR* )
(C++11)
is_pointer
(C++11)
(C++11)
(C++11)
(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_pointer ;
(C++11以降)

std::is_pointer UnaryTypeTrait です。

T オブジェクトまたは関数へのポインタ void へのポインタを含むが、メンバへのポインタは除く)またはそのcv修飾版であるかどうかをチェックします。メンバ定数 value を提供し、 T がオブジェクト/関数ポインタ型の場合、 true に等しくなります。それ以外の場合、 value false に等しくなります。

プログラムが std::is_pointer または std::is_pointer_v に対する特殊化を追加する場合、動作は未定義です。

目次

テンプレートパラメータ

T - チェックする型

ヘルパー変数テンプレート

template < class T >
constexpr bool is_pointer_v = is_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_pointer : std::false_type {};
template<class T>
struct is_pointer<T*> : std::true_type {};
template<class T>
struct is_pointer<T* const> : std::true_type {};
template<class T>
struct is_pointer<T* volatile> : std::true_type {};
template<class T>
struct is_pointer<T* const volatile> : std::true_type {};
(注:指定された条件により、HTMLタグ・属性、 タグ内のC++コード、C++専門用語は翻訳せず、元のフォーマットを保持しています)

#include <type_traits>
int main()
{
    struct A
    {
        int m;
        void f() {}
    };
    int A::*mem_data_ptr = &A::m;     // メンバデータへのポインタ
    void (A::*mem_fun_ptr)() = &A::f; // メンバ関数へのポインタ
    static_assert(
           ! std::is_pointer<A>::value
        && ! std::is_pointer_v<A>    // 上記と同じ、ただしC++17で!
        && ! std::is_pointer<A>()    // 上記と同じ、継承されたoperator boolを使用
        && ! std::is_pointer<A>{}    // 同上
        && ! std::is_pointer<A>()()  // 上記と同じ、継承されたoperator()を使用
        && ! std::is_pointer<A>{}()  // 同上
        &&   std::is_pointer_v<A*>
        &&   std::is_pointer_v<A const* volatile>
        && ! std::is_pointer_v<A&>
        && ! std::is_pointer_v<decltype(mem_data_ptr)>
        && ! std::is_pointer_v<decltype(mem_fun_ptr)>
        &&   std::is_pointer_v<void*>
        && ! std::is_pointer_v<int>
        &&   std::is_pointer_v<int*>
        &&   std::is_pointer_v<int**>
        && ! std::is_pointer_v<int[10]>
        && ! std::is_pointer_v<std::nullptr_t>
        &&   std::is_pointer_v<void (*)()>
    );
}

関連項目

型が非静的メンバー関数またはオブジェクトへのポインタかどうかをチェックする
(クラステンプレート)
型が非静的メンバーオブジェクトポインタかどうかをチェックする
(クラステンプレート)
型が非静的メンバー関数ポインタかどうかをチェックする
(クラステンプレート)
(C++11)
型が配列型かどうかをチェックする
(クラステンプレート)
(C++11)
型がスカラー型かどうかをチェックする
(クラステンプレート)