types_is_virtual_base_of
types_is_virtual_base_of (가상 기본 클래스 여부를 판별하는 타입 특성)
이 페이지에서는 C++26에서 도입된 std::is_virtual_base_of 타입 특성에 대해 설명해요. 이 특성은 어떤 타입이 다른 타입의 가상 기본 클래스인지 컴파일 타임에 확인할 수 있게 해 줘요. 또한 관련 헬퍼 변수 템플릿과 사용 예제도 함께 다룰게요.
출처: cppreference
본문
<type_traits> 헤더에 정의돼 있어요.
template < class Base , class Derived > struct is_virtual_base_of ;
(since 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에 대한 특수화를 추가하면 동작이 정의되지 않아요.
Helper variable template
다음은 헬퍼 변수 템플릿이에요.
template < class Base , class Derived > constexpr bool is_virtual_base_of_v = is_virtual_base_of < Base , Derived >:: value ;
(since C++26)
Inherited from std:: integral_constant
std::is_virtual_base_of는 std::integral_constant에서 상속받아요.
Member constants
value[static] —Base가Derived의 가상 기본 클래스에서 파생된 경우true(cv 한정 무시), 그렇지 않으면false(공용 정적 멤버 상수)
Member functions
operator bool— 객체를bool로 변환하고value를 반환해요 (공용 멤버 함수)operator()(C++14) —value를 반환해요 (공용 멤버 함수)
Member types
| 타입 | 정의 |
|---|---|
value_type |
bool |
type |
std :: integral_constant < bool , value > |
Notes
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예요.
Feature-test macro
| 기능 테스트 매크로 | 값 | 표준 | 기능 |
|---|---|---|---|
__cpp_lib_reflection |
202506L |
(C++26) | <meta>: 리플렉션 라이브러리 지원 |
Example
다음은 사용 예제예요.
#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() {}
See also
| 항목 | 설명 |
|---|---|
is_base_of (C++11) |
한 타입이 다른 타입의 기본 클래스인지 확인해요 (클래스 템플릿) |
is_convertible (C++11), is_nothrow_convertible (C++20) |
한 타입이 다른 타입으로 변환될 수 있는지 확인해요 (클래스 템플릿) |
derived_from (C++20) |
한 타입이 다른 타입에서 파생되었음을 명시해요 (콘셉트) |
is_virtual_base_of_type (C++26) |
두 리플렉션이 한 타입이 다른 타입의 가상 기본 클래스인 타입들을 나타내는지 확인해요 (함수) |
더 알아보기 (Learn more)
원문(English source):
| Defined in header <type_traits> | ||
|---|---|---|
| template < class Base , class Derived > struct is_virtual_base_of ; | (since C++26) |
std::is_virtual_base_of is a BinaryTypeTrait .
Base가 Derived의 가상 기반 클래스라면(cv 한정자 무시) 멤버 상수 value는 true, 아니면 false예요.
Base와 Derived가 모두 유니언이 아닌 클래스 타입이라면(cv 한정자 무시) Derived는 완전 타입(complete type)이어야 해요. 그렇지 않으면 동작이 정의되지 않아요.
프로그램이 std::is_virtual_base_of나 std::is_virtual_base_of_v에 특수화를 추가하면 동작이 정의되지 않아요.
Helper variable template
| template < class Base , class Derived > constexpr bool is_virtual_base_of_v = is_virtual_base_of < Base , Derived >:: value ; | (since C++26) |
|---|
Inherited from std:: integral_constant
Member constants
| value [static] | true if Derived is derived from virtual base class Base (ignoring cv-qualification), false otherwise (public static member constant) |
|---|
Member functions
| operator bool | converts the object to bool , returns value (public member function) |
|---|---|
| operator() (C++14) | returns value (public member function) |
Member types
| Type | Definition |
|---|---|
| value_type | bool |
| type | std :: integral_constant < bool , value > |
Notes
std::is_virtual_base_of_v<A, B>는 A가 B의 private·protected·또는 모호한(ambiguous) 기반 클래스여도 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예요.
| Feature-test macro | Value | Std | Feature |
|---|---|---|---|
| __cpp_lib_reflection | 202506L | (C++26) | : Reflection library support. |
Example
#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() {}
See also
| is_base_of (C++11) | checks if a type is a base of the other type (class template) [edit] |
|---|---|
| is_convertible is_nothrow_convertible (C++11) (C++20) | checks if a type can be converted to the other type (class template) [edit] |
| derived_from (C++20) | specifies that a type is derived from another type (concept) [edit] |
| is_virtual_base_of_type (C++26) | checks if two reflections represent types such that one type is a virtual base of the other type (function) [edit] |