名前空間
変種
操作

std::is_pointer_interconvertible_base_of

From cppreference.com
< cpp‎ | types
 
 
メタプログラミングライブラリ
型特性
型のカテゴリ
(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以降)

もしDerivedBaseから曖昧さなく派生しており、かつすべてのDerivedオブジェクトがそのBaseサブオブジェクトとポインタ相互変換可能である場合、または両方が同じ非共用体クラスである場合(いずれの場合もcv修飾は無視)、メンバ定数valuetrueに等しくなります。それ以外の場合、valuefalseになります。

もしBaseDerivedの両方が非共用体クラス型であり、それらが同じ型でない場合(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]
もしDerivedBaseから曖昧さなく派生しており、かつすべての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>は、TUのprivateまたはprotectedな基底クラスである場合でもtrueになることがあります。

以下とする:

  • Uは完全なオブジェクト型、
  • TUと同等以上のcv修飾を持つ完全なオブジェクト型、
  • 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)
型が非静的データメンバを持たないクラス型(共用体ではない)であるかをチェックする
(クラステンプレート) [編集]
型がスタンダードレイアウト型であるかをチェックする
(クラステンプレート) [編集]
English 日本語 中文(简体) 中文(繁體)