types_is_union

types_is_union (유니온 타입 판별)

std::is_union은 주어진 타입 T가 유니온(union) 타입인지 확인하는 타입 특성입니다. 컴파일 타임에 value라는 상수 멤버를 통해 결과를 제공하며, true 또는 false로 판별됩니다. 이 페이지에서는 사용법과 상속받은 멤버들을 해요체로 설명합니다.

출처: cppreference

본문

<type_traits> 헤더에 정의되어 있어요.

Defined in header <type_traits>
template < class T > struct is_union ; (since C++11)

std::is_union은 UnaryTypeTrait 입니다.

T가 유니온 타입인지 확인해요. T가 유니온 타입이면 멤버 상수 valuetrue가 되고, 그렇지 않으면 false가 됩니다.

프로그램에서 std::is_union 또는 std::is_union_v에 대한 특수화를 추가하면 동작이 정의되지 않아요.

템플릿 매개변수

T - 확인할 타입

헬퍼 변수 템플릿

template < class T > constexpr bool is_union_v = is_union < T >:: value ; (since C++17)

std::integral_constant에서 상속받은 멤버

멤버 상수

value [static] T가 유니온 타입이면 true, 아니면 false (공용 정적 멤버 상수)

멤버 함수

operator bool 객체를 bool로 변환하고 value를 반환해요 (공용 멤버 함수)
operator() (C++14) value를 반환해요 (공용 멤버 함수)

멤버 타입

Type Definition
value_type bool
type std :: integral_constant < bool , value >

예제

#include <type_traits>

struct A {};
static_assert(!std::is_union_v<A>);

typedef union
{
    int a;
    float b;
} B;
static_assert(std::is_union_v<B>);

struct C { B d; };
static_assert(!std::is_union_v<C>);

static_assert(!std::is_union_v<int>);

int main() {}

같이 보기

is_class (C++11) 비유니온 클래스 타입인지 확인해요 (클래스 템플릿) [edit]
is_union_type (C++26) 반영된 타입이 유니온 타입인지 확인해요 (함수) [edit]

더 알아보기 (Learn more)

cppreference