std::is_implicit_lifetime
來自 cppreference.com
定義於標頭檔案 <type_traits> |
||
template< class T > struct is_implicit_lifetime; |
(C++23 起) | |
std::is_implicit_lifetime
是一個 UnaryTypeTrait。
如果 T
是一個隱式生命週期型別,則提供等於 true 的成員常量 value。對於任何其他型別,value 為 false。
如果 T 是一個不完整型別,且不是陣列型別或(可能帶有 cv 限定符的)void,則行為是未定義的。
如果程式為 std::is_implicit_lifetime
或 std::is_implicit_lifetime_v
新增特化,則行為是未定義的。
目錄 |
[編輯] 模板引數
T | - | 要檢查的型別 |
[編輯] 輔助變數模板
template< class T > constexpr bool is_implicit_lifetime_v = is_implicit_lifetime<T>::value; |
(C++23 起) | |
繼承自 std::integral_constant
成員常量
value [靜態] |
true 如果 T 是隱式生命週期型別,否則為 false(public static 成員常量) |
成員函式
operator bool |
將物件轉換為 bool,返回 value (公開成員函式) |
operator() (C++14) |
返回 value (公開成員函式) |
成員型別
型別 | 定義 |
value_type
|
bool |
型別
|
std::integral_constant<bool, value> |
[編輯] 注意
特性測試宏 | 值 | 標準 | 特性 |
---|---|---|---|
__cpp_lib_is_implicit_lifetime |
202302L |
(C++23) | std::is_implicit_lifetime
|
[編輯] 示例
執行此程式碼
// The following types are collectively called implicit-lifetime types: // * scalar types: // * arithmetic types // * enumeration types // * pointer types // * pointer-to-member types // * std::nullptr_t // * implicit-lifetime class types // * is an aggregate whose destructor is not user-provided // * has at least one trivial eligible constructor and a trivial, // non-deleted destructor // * array types // * cv-qualified versions of these types. #include <type_traits> static_assert(std::is_implicit_lifetime_v<int>); // arithmetic type is a scalar type static_assert(std::is_implicit_lifetime_v<const int>); // cv-qualified a scalar type enum E { e }; static_assert(std::is_implicit_lifetime_v<E>); // enumeration type is a scalar type static_assert(std::is_implicit_lifetime_v<int*>); // pointer type is a scalar type static_assert(std::is_implicit_lifetime_v<std::nullptr_t>); // scalar type struct S { int x, y; }; // S is an implicit-lifetime class: an aggregate without user-provided destructor static_assert(std::is_implicit_lifetime_v<S>); static_assert(std::is_implicit_lifetime_v<int S::*>); // pointer-to-member struct X { ~X() = delete; }; // X is not implicit-lifetime class due to deleted destructor static_assert(!std::is_implicit_lifetime_v<X>); static_assert(std::is_implicit_lifetime_v<int[8]>); // array type static_assert(std::is_implicit_lifetime_v<volatile int[8]>); // cv-qualified array type int main() {}
[編輯] 參閱
(C++11) |
檢查型別是否為標量型別 (類模板) |
(C++11) |
檢查型別是否為陣列型別 (類模板) |
(C++17) |
檢查型別是否為聚合型別 (類模板) |
在給定儲存中隱式建立物件,並重用物件表示 (函式模板) |