Namespaces
Variants

std:: is_null_pointer

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

std::is_null_pointer UnaryTypeTrait です。

T が型 std::nullptr_t であるかどうかをチェックします。

メンバ定数 value を提供します。これは、 T が型 std::nullptr_t const std:: nullptr_t volatile std:: nullptr_t または const volatile std:: nullptr_t である場合に true に等しくなります。

それ以外の場合、 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]
true もし T が型 std::nullptr_t (CV修飾可能性あり) の場合、 false それ以外の場合
(公開静的メンバ定数)

メンバ関数

operator bool
オブジェクトを bool に変換、 value を返す
(公開メンバ関数)
operator()
(C++14)
value を返す
(公開メンバ関数)

メンバ型

定義
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 false を返します。なぜなら std::nullptr_t は組み込みポインタ型ではないためです。

libc++では、 std::is_null_pointer はC++11モードでは利用できません。

機能テスト マクロ 標準 機能
__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)
型がオブジェクト型かどうかチェックする
(クラステンプレート)