std::is_pod
來自 cppreference.com
| 定義於標頭檔案 <type_traits> |
||
| template< class T > struct is_pod; |
(C++11 起) (C++20 中已棄用) |
|
std::is_pod 是一個 UnaryTypeTrait。
若 T 是 POD 型別(“純舊資料型別”),則提供成員常量 value 等於 true。對於任何其他型別,value 為 false。
若 std::remove_all_extents_t<T> 是不完整型別且非(可能 cv 限定的)void,則行為未定義。
若程式為 std::is_pod 或 std::is_pod_v 新增特化,則行為未定義。
目錄 |
[編輯] 模板引數
| T | - | 要檢查的型別 |
[編輯] 輔助變數模板
| template< class T > constexpr bool is_pod_v = is_pod<T>::value; |
(C++17 起) (C++20 中已棄用) |
|
繼承自 std::integral_constant
成員常量
| value [靜態] |
若 T 是 POD 型別,則為 true,否則為 false。(public static 成員常量) |
成員函式
| operator bool |
將物件轉換為 bool,返回 value (公開成員函式) |
| operator() (C++14) |
返回 value (公開成員函式) |
成員型別
| 型別 | 定義 |
value_type
|
bool |
型別
|
std::integral_constant<bool, value> |
[編輯] 示例
執行此程式碼
#include <type_traits> struct A { int m; }; static_assert(std::is_pod_v<A> == true); class B: public A { int m; }; static_assert(std::is_pod_v<B> == false); struct C { virtual void foo(); }; static_assert(std::is_pod_v<C> == false); int main() {}
[編輯] 缺陷報告
下列更改行為的缺陷報告追溯地應用於以前出版的 C++ 標準。
| 缺陷報告 | 應用於 | 釋出時的行為 | 正確的行為 |
|---|---|---|---|
| LWG 2015 | C++11 | T 可以是不完整型別的陣列未知邊界的類型別 |
在這種情況下,行為是 未定義的 |
[編輯] 參見
| (C++11) |
檢查型別是否為標準佈局型別 (類模板) |
| (C++11)(C++26 中已棄用) |
檢查型別是否為平凡型別 (類模板) |
| (C++11) |
檢查型別是否為標量型別 (類模板) |
[編輯] 外部連結
為什麼 std::is_pod 在 C++20 中被棄用? — StackOverflow |