std::is_null_pointer

定义于头文件 <type_traits>
template< class T >
struct is_null_pointer;
(C++14 起)

检查 T 是否为 std::nullptr_t 类型。

Tstd::nullptr_tconst std::nullptr_tvolatile std::nullptr_tconst volatile std::nullptr_t 类型,则提供等于 true 的成员常量 value

否则, value 等于 false

目录

模板形参

T - 要检查的类型

辅助变量模板

template< class T >
inline constexpr bool is_null_pointer_v = is_null_pointer<T>::value;
(C++17 起)

继承自 std::integral_constant

成员常量

value
[静态]
T 为(可有 cv 限定的) std::nullptr_t 类型则为 true ,否则为 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, typename std::remove_cv<T>::type> {};

注意

对于 std::nullptr_tstd::is_pointerfalse ,因为它不是内建指针类型。

示例

#include <iostream>
#include <type_traits>
 
int main()
{
    std::cout << std::boolalpha
              << std::is_null_pointer< decltype(nullptr) >::value << ' '
              << std::is_null_pointer< int* >::value << '\n'
              << std::is_pointer< decltype(nullptr) >::value << ' '
              << std::is_pointer<int*>::value << '\n';
}

输出:

true false
false true

参阅

(C++11)
检查类型是否为 void
(类模板)
(C++11)
检查类型是否是数组类型
(类模板)
(C++11)
检查类型是否为指针类型
(类模板)
(C++11)
检查类型是否是枚举类型
(类模板)
(C++11)
检查类型是否联合体类型
(类模板)
(C++11)
检查类型是否非联合类类型
(类模板)
(C++11)
检查是否为函数类型
(类模板)
(C++11)
检查是否是对象类型
(类模板)

版本历史

  • (当前 | 先前 2017年11月17日 (五) 04:42Fruderica讨论 | 贡献. . (1,901字节) (+153). . (撤销)
  • 当前 | 先前 2017年11月17日 (五) 04:41Fruderica讨论 | 贡献 . . (1,748字节) (-217). . (形参/辅助) (撤销)
  • 当前 | 先前 2017年3月18日 (六) 10:07Fruderica讨论 | 贡献 . . (1,965字节) (+3). . (撤销)
  • 当前 | 先前) 2017年3月18日 (六) 09:59Fruderica讨论 | 贡献. . (1,962字节) (+1,962). . (以“{{cpp/title|is_null_pointer}} {{cpp/types/navbar}} {{dcl begin}} {{dcl header | type_traits}} {{dcl | since=c++14 | 1= template< class T > struct is_null_pointer; }}...”为内容创建页面)