◐ Shell
clean mode source ↗

std::is_pointer - cppreference.com

提供: cppreference.com

<tbody> </tbody>

template< class T > struct is_pointer;

(C++11以上)

Tオブジェクトへのポインタまたは関数へのポインタである (しかしメンバへのポインタやメンバ関数へのポインタではない) かどうか調べます。 T がオブジェクトポインタ型または関数ポインタ型であれば、 true に等しいメンバ定数 value が提供されます。 そうでなければ、 valuefalse に等しくなります。

is_pointer または is_pointer_v (C++17以上) に対して特殊化を追加するプログラムは未定義です。

テンプレート引数

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

<tbody> </tbody>

template< class T > inline constexpr bool is_pointer_v = is_pointer<T>::value;

(C++17以上)

std::integral_constant から継承

メンバ定数

T がポインタ型ならば true、そうでなければ false
(パブリック静的メンバ定数)

メンバ関数

オブジェクトを bool に変換します。 value を返します
(パブリックメンバ関数)
value を返します
(パブリックメンバ関数)

メンバ型

定義
value_type bool
type std::integral_constant<bool, value>

実装例

template< class T > struct is_pointer_helper     : std::false_type {};
template< class T > struct is_pointer_helper<T*> : std::true_type {};
template< class T > struct is_pointer : is_pointer_helper<typename std::remove_cv<T>::type> {};

#include <iostream>
#include <type_traits>

class A {};

int main() 
{
    std::cout << std::boolalpha;
    std::cout << std::is_pointer<A>::value << '\n';
    std::cout << std::is_pointer<A *>::value << '\n';
    std::cout << std::is_pointer<A &>::value << '\n';
    std::cout << std::is_pointer<int>::value << '\n';
    std::cout << std::is_pointer<int *>::value << '\n';
    std::cout << std::is_pointer<int **>::value << '\n';
    std::cout << std::is_pointer<int[10]>::value << '\n';
    std::cout << std::is_pointer<std::nullptr_t>::value << '\n';
}

出力:

false
true
false
false
true
true
false
false

関連項目