std:: is_pointer
| Type traits | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Compile-time rational arithmetic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Compile-time integer sequences | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
(C++14)
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
ヘッダーで定義
<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 {}; |
タグ内の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)
|
型が非静的メンバーオブジェクトポインタかどうかをチェックする
(クラステンプレート) |
|
(C++11)
|
型が非静的メンバー関数ポインタかどうかをチェックする
(クラステンプレート) |
|
(C++11)
|
型が配列型かどうかをチェックする
(クラステンプレート) |
|
(C++11)
|
型がスカラー型かどうかをチェックする
(クラステンプレート) |