std::is_pointer_interconvertible_base_of
來自 cppreference.com
定義於標頭檔案 <type_traits> |
||
template< class Base, class Derived > struct is_pointer_interconvertible_base_of; |
(C++20 起) | |
如果 Derived
明確地派生自 Base
且每個 Derived
物件與它的 Base
子物件是指標可互轉的,或者如果兩者都是相同的非聯合類(在兩種情況下都忽略 cv-限定符),則提供成員常量 value
等於 true。否則 value
為 false。
如果 Base
和 Derived
都是非聯合類型別,並且它們不是相同的型別(忽略 cv-限定符),則 Derived
應是完整型別;否則行為是未定義的。
如果程式為 std::is_pointer_interconvertible_base_of
或 std::is_pointer_interconvertible_base_of_v
新增特化,則行為是未定義的。
目錄 |
[編輯] 輔助變數模板
template< class Base, class Derived > inline constexpr bool is_pointer_interconvertible_base_of_v = |
(C++20 起) | |
繼承自 std::integral_constant
成員常量
value [靜態] |
如果 Derived 明確地派生自 Base 且每個 Derived 物件與它的 Base 子物件是指標可互轉的,或者如果兩者都是相同的非聯合類(在兩種情況下都忽略 cv-限定符),則為 true,否則為 false(public static 成員常量) |
成員函式
operator bool |
將物件轉換為 bool,返回 value (公開成員函式) |
operator() (C++14) |
返回 value (公開成員函式) |
成員型別
型別 | 定義 |
value_type
|
bool |
型別
|
std::integral_constant<bool, value> |
[編輯] 註解
std::is_pointer_interconvertible_base_of_v<T, U> 即使 T
是 U
的私有或保護基類也可能為 true。
令
-
U
為完整物件型別, -
T
為 cv-限定符不弱於U
的完整物件型別, -
u
為U
的任意有效左值,
如果 std::is_pointer_interconvertible_base_of_v<T, U> 為 true,則 reinterpret_cast<T&>(u) 總是具有定義良好的結果。
如果 T
和 U
不是相同的型別(忽略 cv-限定符)且 T
是 U
的指標可互轉基類,則 std::is_standard_layout_v<T> 和 std::is_standard_layout_v<U> 都為 true。
如果 T
是標準佈局類型別,則 T
的所有基類(如果有)都是 T
的指標可互轉基類。
特性測試宏 | 值 | 標準 | 特性 |
---|---|---|---|
__cpp_lib_is_pointer_interconvertible |
201907L |
(C++20) | 指標可互轉特性
|
[編輯] 示例
執行此程式碼
#include <type_traits> struct Foo {}; struct Bar {}; class Baz : Foo, public Bar { int x; }; class NonStdLayout : public Baz { int y; }; static_assert(std::is_pointer_interconvertible_base_of_v<Bar, Baz>); static_assert(std::is_pointer_interconvertible_base_of_v<Foo, Baz>); static_assert(not std::is_pointer_interconvertible_base_of_v<Baz, NonStdLayout>); static_assert(std::is_pointer_interconvertible_base_of_v<NonStdLayout, NonStdLayout>); int main() {}
[編輯] 參閱
(C++11) |
檢查一個型別是否為另一個型別的基類 (類模板) |
(C++11) |
檢查型別是否為類(而非聯合)型別且沒有非靜態資料成員 (類模板) |
(C++11) |
檢查型別是否為標準佈局型別 (類模板) |