std::is_pointer_interconvertible_base_of
| ヘッダ <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 [static] |
もしDerivedがBaseから曖昧さなく派生しており、かつすべてのDerivedオブジェクトがそのBaseサブオブジェクトとポインタ相互変換可能である場合、または両方が同じ非共用体クラスである場合(いずれの場合もcv修飾は無視)、true、それ以外の場合false(公開静的メンバ定数) |
メンバ関数
| operator bool |
オブジェクトを bool に変換し、value を返します。 (public member function) |
| operator() (C++14) |
value を返します。 (public member function) |
メンバ型
| 型 | 定義 |
value_type
|
bool |
type
|
std::integral_constant<bool, value> |
[編集] 備考
std::is_pointer_interconvertible_base_of_v<T, U>は、TがUのprivateまたはprotectedな基底クラスである場合でもtrueになることがあります。
以下とする:
-
Uは完全なオブジェクト型、 -
TはUと同等以上のcv修飾を持つ完全なオブジェクト型、 -
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) |
型がスタンダードレイアウト型であるかをチェックする (クラステンプレート) |