std::is_null_pointer
來自 cppreference.com
定義於標頭檔案 <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 [靜態] |
如果 T 是型別 std::nullptr_t(可能帶 cv 限定符),則為 true,否則為 false。(public static 成員常量) |
成員函式
operator bool |
將物件轉換為 bool,返回 value (公開成員函式) |
operator() (C++14) |
返回 value (公開成員函式) |
成員型別
型別 | 定義 |
value_type
|
bool |
型別
|
std::integral_constant<bool, value> |
[編輯部分:可能實現] 可能實現
template<class T> struct is_null_pointer : std::is_same<std::nullptr_t, std::remove_cv_t<T>> {}; |
[編輯部分:註解] 註解
對於 std::nullptr_t,std::is_pointer 為 false,因為它不是一個內建指標型別。
在 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++ 標準。
缺陷報告 | 應用於 | 釋出時的行為 | 正確的行為 |
---|---|---|---|
LWG 2247 | C++11 | 缺少用於檢測 std::nullptr_t 的型別特性 | 已新增 |
[編輯部分:參閱] 參閱
(C++11) |
檢查型別是否為 void (類模板) |
(C++11) |
檢查型別是否為陣列型別 (類模板) |
(C++11) |
檢查型別是否為指標型別 (類模板) |
(C++11) |
檢查一個型別是否是列舉型別 (類模板) |
(C++11) |
檢查型別是否為聯合型別 (類模板) |
(C++11) |
檢查型別是否為非聯合類型別 (類模板) |
(C++11) |
檢查型別是否為函式型別 (類模板) |
(C++11) |
檢查型別是否為物件型別 (類模板) |