std::is_null_pointer
From cppreference.com
| ヘッダ <type_traits> で定義 |
||
| template< class T > struct is_null_pointer; |
(C++11以降) | |
std::is_null_pointer は、UnaryTypeTrait です。
T が型 std::nullptr_t であるかをチェックします。
T が型 std::nullptr_t、const std::nullptr_t、volatile std::nullptr_t、または const volatile std::nullptr_t の場合、true に等しいメンバー定数 value を提供します。
それ以外の場合、value は false に等しくなります。
プログラムが std::is_null_pointer または std::is_null_pointer_v(C++17 以降) の特殊化を追加した場合、その動作は未定義です。
目次 |
[編集] テンプレートパラメータ
| T | - | チェックする型 |
[編集] ヘルパー変数テンプレート
| template< class T > constexpr bool is_null_pointer_v = is_null_pointer<T>::value; |
(C++17以降) | |
std::integral_constant から継承
メンバ定数
| value [static] |
T が std::nullptr_t 型 (cv-qualified されている可能性あり) の場合は 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_null_pointer : std::is_same<std::nullptr_t, std::remove_cv_t<T>> {}; |
[編集] 注釈
std::is_pointer は、std::nullptr_t については false となります。これは、ビルトインのポインタ型ではないためです。
libc++ では、C++11 モードで std::is_null_pointer は利用できません。
| 機能テストマクロ | 値 | 規格 | 機能 |
|---|---|---|---|
__cpp_lib_is_null_pointer |
201309L |
(C++14) (DR11) |
std::is_null_pointer
|
[編集] 例
このコードを実行
#include <type_traits> static_assert(std::is_null_pointer_v<decltype(nullptr)>); static_assert(!std::is_null_pointer_v<int*>); static_assert(!std::is_pointer_v<decltype(nullptr)>); static_assert(std::is_pointer_v<int*>); int main() { }
[編集] 欠陥報告
以下の動作変更を伴う欠陥報告が、以前に公開されたC++標準に遡って適用されました。
| DR | 適用対象 | 公開された動作 | 正しい動作 |
|---|---|---|---|
| LWG 2247 | C++11 | std::nullptr_t を検出するための型特性が欠落していました。 | 追加された |
[編集] 関連項目
| (C++11) |
型が void であるかをチェックする (クラステンプレート) |
| (C++11) |
型が配列型であるかをチェックする (クラステンプレート) |
| (C++11) |
型がポインタ型であるかをチェックする (クラステンプレート) |
| (C++11) |
型が列挙型であるかをチェックする (クラステンプレート) |
| (C++11) |
型が共用体型であるかをチェックする (クラステンプレート) |
| (C++11) |
型が共用体でないクラス型であるかをチェックする (クラステンプレート) |
| (C++11) |
型が関数型であるかをチェックする (クラステンプレート) |
| (C++11) |
型がオブジェクト型であるかをチェックする (クラステンプレート) |