名稱空間
變體
操作

std::is_pointer_interconvertible_base_of

來自 cppreference.com
< cpp‎ | 型別
 
 
超程式設計庫
型別特性
型別類別
(C++11)
(C++11)(DR*)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11) 
(C++11)
(C++11)
型別屬性
(C++11)
(C++11)
(C++14)
(C++11)(C++26 中已棄用)
(C++11)(直到 C++20*)
(C++11)(C++20 中已棄用)
(C++11)
型別特性常量
元函式
(C++17)
支援的操作
關係與屬性查詢
型別修改
(C++11)(C++11)(C++11)
型別轉換
(C++11)(C++23 中已棄用)
(C++11)(C++23 中已棄用)
(C++11)
(C++11)(直到 C++20*)(C++17)

(C++11)
(C++17)
編譯時有理數算術
編譯時整數序列
 
定義於標頭檔案 <type_traits>
template< class Base, class Derived >
struct is_pointer_interconvertible_base_of;
(C++20 起)

如果 Derived 明確地派生自 Base 且每個 Derived 物件與它的 Base 子物件是指標可互轉的,或者如果兩者都是相同的非聯合類(在兩種情況下都忽略 cv-限定符),則提供成員常量 value 等於 true。否則 valuefalse

如果 BaseDerived 都是非聯合類型別,並且它們不是相同的型別(忽略 cv-限定符),則 Derived 應是完整型別;否則行為是未定義的。

如果程式為 std::is_pointer_interconvertible_base_ofstd::is_pointer_interconvertible_base_of_v 新增特化,則行為是未定義的。

目錄

[編輯] 輔助變數模板

template< class Base, class Derived >

inline constexpr bool is_pointer_interconvertible_base_of_v =

    is_pointer_interconvertible_base_of<Base, Derived>::value;
(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> 即使 TU 的私有或保護基類也可能為 true

  • U 為完整物件型別,
  • T 為 cv-限定符不弱於 U 的完整物件型別,
  • uU 的任意有效左值,

如果 std::is_pointer_interconvertible_base_of_v<T, U>true,則 reinterpret_cast<T&>(u) 總是具有定義良好的結果。

如果 TU 不是相同的型別(忽略 cv-限定符)且 TU 的指標可互轉基類,則 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)
檢查型別是否為類(而非聯合)型別且沒有非靜態資料成員
(類模板) [編輯]
檢查型別是否為標準佈局型別
(類模板) [編輯]