std::is_pointer
From cppreference.com
| ヘッダ <type_traits> で定義 |
||
| template< class T > struct is_pointer; |
(C++11以降) | |
std::is_pointer は、単項型特性 です。
T が オブジェクトまたは関数へのポインタ (void へのポインタを含むが、メンバへのポインタは除く) であるか、またはその cv-修飾バージョンであるかをチェックします。T がオブジェクト/関数ポインタ型である場合、true に等しいメンバ定数 value を提供します。そうでない場合、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] |
T がポインタ型の場合 true、そうでなければ false(公開静的メンバ定数) |
メンバ関数
| 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 {}; |
[編集] 例
このコードを実行
#include <type_traits> int main() { struct A { int m; void f() {} }; int A::*mem_data_ptr = &A::m; // a pointer to member data void (A::*mem_fun_ptr)() = &A::f; // a pointer to member function static_assert( ! std::is_pointer<A>::value && ! std::is_pointer_v<A> // same thing as above, but in C++17! && ! std::is_pointer<A>() // same as above, using inherited operator bool && ! std::is_pointer<A>{} // ditto && ! std::is_pointer<A>()() // same as above, using inherited operator() && ! std::is_pointer<A>{}() // ditto && 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) |
型がスカラ型であるかをチェックする (クラステンプレート) |