Namespaces
Variants

std:: is_virtual_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
(C++11)
is_virtual_base_of
(C++26)
(C++11)
(C++11)
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_virtual_base_of ;
(C++26以降)

std::is_virtual_base_of BinaryTypeTrait です。

Base Derived 仮想基本クラス である場合(CV修飾を無視)、メンバ定数 value true に等しい値を提供します。それ以外の場合、 value false です。

Base Derived の両方が非共用体クラス型(CV修飾を無視)である場合、 Derived 完全型 でなければならない。そうでない場合、動作は未定義となる。

プログラムが std::is_virtual_base_of または std::is_virtual_base_of_v に対する特殊化を追加する場合、動作は未定義です。

目次

ヘルパー変数テンプレート

template < class Base, class Derived >
constexpr bool is_virtual_base_of_v = is_virtual_base_of < Base, Derived > :: value ;
(C++26以降)

std::integral_constantから継承

メンバ定数

value
[static]
true Derived が仮想基底クラス Base から派生している場合(CV修飾を無視))、 false (それ以外の場合)
(公開静的メンバ定数)

メンバ関数

operator bool
オブジェクトを bool に変換し、 value を返す
(公開メンバ関数)
operator()
(C++14)
value を返す
(公開メンバ関数)

メンバ型

定義
value_type bool
type std:: integral_constant < bool , value >

注記

std :: is_virtual_base_of_v < A, B > は、 A B のprivate、protected、または曖昧な基底クラスである場合でも true となります。

std :: is_virtual_base_of_v < A, B > true の場合、 std:: is_base_of_v < A, B > true となります。しかし、逆は常に真ではありません。なぜなら仮想継承のチェックはより特化的なためです。その場合、 std :: is_virtual_base_of_v < T, T > は、 T が非共用体クラス型であっても false となります。

#include <type_traits>
class A {};
class B : A {};
class C : B {};
class D : virtual A {};
class E : D {};
union F {};
using I = int;
static_assert
(
    std::is_virtual_base_of_v<A, A> != true &&
    std::is_virtual_base_of_v<A, B> != true &&
    std::is_virtual_base_of_v<A, D> == true &&
    std::is_virtual_base_of_v<D, E> != true &&
    std::is_virtual_base_of_v<F, F> != true &&
    std::is_virtual_base_of_v<I, I> != true
);
int main() {}

関連項目

(C++11)
ある型が別の型の基底型であるかどうかをチェックする
(クラステンプレート)
ある型が別の型に変換可能かどうかをチェックする
(クラステンプレート)
ある型が別の型から派生していることを指定する
(コンセプト)