types_is_compound
types_is_compound (복합 타입 판별)
std::is_compound은 주어진 타입 T가 복합 타입(compound type)인지 판별하는 UnaryTypeTrait예요. 배열, 함수, 포인터, 참조, 클래스, 공용체, 열거형 등 기본 타입에서 파생된 모든 타입에 대해 true를 제공해요. 이 페이지에서는 std::is_compound의 정의, 사용법, 예제를 자세히 살펴볼게요.
출처: cppreference
본문
정의
<type_traits> 헤더에 정의되어 있으며, C++11부터 사용할 수 있어요.
Defined in header <type_traits> |
||
|---|---|---|
template < class T > struct is_compound ; |
(since C++11) |
동작 방식
std::is_compound은 UnaryTypeTrait예요.
T가 복합 타입(즉, 배열, 함수, 객체 포인터, 함수 포인터, 멤버 객체 포인터, 멤버 함수 포인터, 참조, 클래스, 공용체, 열거형이며 cv 한정 변형을 포함)이라면 멤버 상수 value는 true예요. 그 외의 모든 타입에 대해서는 value가 false예요.
프로그램에서 std::is_compound나 std::is_compound_v에 대한 특수화를 추가하면 동작이 정의되지 않아요.
템플릿 매개변수
| T | - | 확인할 타입 |
|---|
헬퍼 변수 템플릿
C++17부터 다음 헬퍼 변수 템플릿을 사용할 수 있어요.
template < class T > constexpr bool is_compound_v = is_compound < 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 > |
참고 사항
복합 타입은 기본 타입(fundamental type)으로부터 구성된 타입이에요. 모든 C++ 타입은 기본 타입이거나 복합 타입이에요.
가능한 구현
template < class T > struct is_compound : std :: integral_constant < bool , ! std :: is_fundamental < T >:: value > {};
예제
#include <type_traits>
#include <iostream>
static_assert(not std::is_compound_v<int>);
static_assert(std::is_compound_v<int*>);
static_assert(std::is_compound_v<int&>);
void f();
static_assert(std::is_compound_v<decltype(f)>);
static_assert(std::is_compound_v<decltype(&f)>);
static_assert(std::is_compound_v<char[100]>);
class C {};
static_assert(std::is_compound_v<C>);
union U {};
static_assert(std::is_compound_v<U>);
enum struct E { e };
static_assert(std::is_compound_v<E>);
static_assert(std::is_compound_v<decltype(E::e)>);
struct S
{
int i : 8;
int j;
void foo();
};
static_assert(not std::is_compound_v<decltype(S::i)>);
static_assert(not std::is_compound_v<decltype(S::j)>);
static_assert(std::is_compound_v<decltype(&S::j)>);
static_assert(std::is_compound_v<decltype(&S::foo)>);
int main()
{
std::cout << "All checks have passed\n";
}
같이 보기
is_fundamental (C++11) |
타입이 기본 타입인지 확인해요 (클래스 템플릿) |
|---|---|
is_scalar (C++11) |
타입이 스칼라 타입인지 확인해요 (클래스 템플릿) |
| --- | --- |
is_object (C++11) |
타입이 객체 타입인지 확인해요 (클래스 템플릿) |
| --- | --- |
is_array (C++11) |
타입이 배열 타입인지 확인해요 (클래스 템플릿) |
| --- | --- |
is_compound_type (C++26) |
반영된 타입이 복합 타입인지 확인해요 (함수) |
| --- | --- |