types_is_enum

types_is_enum (열거형 타입인지 검사하는 특성)

이 페이지는 C++ 표준 라이브러리의 std::is_enum 타입 특성(type trait)에 대해 설명해요. std::is_enum은 주어진 타입이 열거형(enumeration)인지 컴파일 타임에 판별하는 데 사용돼요. 이 특성은 <type_traits> 헤더에서 제공되며, C++11부터 사용할 수 있어요.

출처: cppreference

본문

헤더에 정의됨

<type_traits>에 정의됨
template < class T > struct is_enum ; (C++11부터)

std::is_enum은 UnaryTypeTrait입니다.

T가 열거형 타입인지 검사해요. T가 열거형 타입이면 멤버 상수 valuetrue가 되고, 그렇지 않으면 valuefalse가 돼요.

프로그램에서 std::is_enum이나 std::is_enum_v에 대한 특수화를 추가하면 동작이 정의되지 않아요(undefined behavior).

템플릿 매개변수

T - 검사할 타입

도우미 변수 템플릿

template < class T > constexpr bool is_enum_v = is_enum < T >:: value ; (C++17부터)

std::integral_constant에서 상속됨

멤버 상수

value [static] T가 열거형 타입이면 true, 그렇지 않으면 false (공용 정적 멤버 상수)

멤버 함수

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

멤버 타입

타입 정의
value_type bool
type std :: integral_constant < bool , value >

예제

#include <type_traits>

struct A { enum E { e }; };
static_assert(!std::is_enum_v<A>);
static_assert(std::is_enum_v<A::E>);
static_assert(std::is_enum_v<decltype(A::E::e)>);

enum E {};
static_assert(std::is_enum_v<E>);
static_assert(std::is_enum_v<const E>, "Constness is ignored");
static_assert(!std::is_enum_v<E&>, "References matter");

enum class E1 : int { e };
static_assert(std::is_enum_v<E1>);
static_assert(std::is_enum_v<decltype(E1::e)>);

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

enum class E2;
static_assert(std::is_enum_v<E2>, "Forward-declared scoped enum");

enum class E3 : char;
static_assert(std::is_enum_v<E3>, "Forward-declared scoped enum with explicit base type");

int main() {}

같이 보기

is_integral (C++11) 타입이 정수 타입인지 검사해요 (클래스 템플릿) [편집]
is_arithmetic (C++11) 타입이 산술 타입인지 검사해요 (클래스 템플릿) [편집]
is_scalar (C++11) 타입이 스칼라 타입인지 검사해요 (클래스 템플릿) [편집]
is_scoped_enum (C++23) 타입이 스코프 있는 열거형 타입인지 검사해요 (클래스 템플릿) [편집]
is_enumerator (C++26) 리플렉션이 열거자를 나타내는지 검사해요 (함수) [편집]
is_enum_type (C++26) 반영된 타입이 열거형 타입인지 검사해요 (함수) [편집]

더 알아보기 (Learn more)

cppreference