Namespaces
Variants

std:: is_pointer_interconvertible_base_of

From cppreference.net
Metaprogramming library
Type traits
Type categories
(C++11)
(C++11) ( DR* )
Type properties
(C++11)
(C++11)
(C++14)
(C++11) (deprecated in C++26)
(C++11) ( until C++20* )
(C++11) (deprecated in C++20)
(C++11)
Type trait constants
Metafunctions
(C++17)
Supported operations
Relationships and property queries
Type modifications
Type transformations
(C++11) (deprecated in C++23)
(C++11) (deprecated in C++23)
(C++11)
(C++11) ( until C++20* ) (C++17)

Compile-time rational arithmetic
Compile-time integer sequences
ヘッダーで定義 <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 =

is_pointer_interconvertible_base_of < Base, Derived > :: value ;
(C++20以降)

std::integral_constantから継承

メンバ定数

value
[static]
true の場合、 Derived Base から明確に派生しており、かつすべての Derived オブジェクトがその Base 部分オブジェクトと ポインタ相互変換可能 である場合、または両方が同じ非共用体クラスである場合(いずれの場合もCV修飾を無視)、 false それ以外の場合
(public static member constant)

メンバ関数

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 型の任意の有効な左辺値、

reinterpret_cast < T & > ( u ) は、 std :: is_pointer_interconvertible_base_of_v < T, U > true の場合、常に明確に定義された結果を持ちます。

T U が(CV修飾を無視して)異なる型であり、かつ T U のポインタ相互変換可能な基底クラスである場合、 std:: is_standard_layout_v < T > std:: is_standard_layout_v < U > はともに true となります。

T がstandard layoutクラス型の場合、 T のすべての基底クラス(存在する場合)は T のpointer-interconvertible基底クラスです。

機能テスト マクロ 標準 機能
__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)
型がクラス型(ただし共用体ではない)であり、非静的データメンバーを持たないかどうかをチェックする
(クラステンプレート)
型が スタンダードレイアウト 型であるかどうかをチェックする
(クラステンプレート)