types_is_bounded_array

types_is_bounded_array (경계가 알려진 배열 타입인지 확인하는 타입 특질)

std::is_bounded_array는 C++20에서 도입된 UnaryTypeTrait로, 주어진 타입 T가 경계(크기)가 알려진 배열 타입인지 확인하는 템플릿이에요. 이 페이지에서는 이 타입 특질의 정의, 사용법, 구현 예시와 관련 기능을 함께 살펴볼게요.

출처: cppreference

본문

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

std::is_bounded_array는 UnaryTypeTrait로, T가 경계가 알려진 배열 타입인지 검사해요. T가 경계가 알려진 배열 타입이면 멤버 상수 valuetrue가 되고, 그렇지 않으면 valuefalse가 돼요.

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

템플릿 매개변수

T - 확인할 타입

헬퍼 변수 템플릿

template < class T > constexpr bool is_bounded_array_v = is_bounded_array<T>::value; (since C++20)

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>

가능한 구현

template<class T> struct is_bounded_array : std::false_type {}; template<class T, std::size_t N> struct is_bounded_array<T[N]> : std::true_type {};

참고 사항

기능 테스트 매크로 표준 기능
__cpp_lib_bounded_array_traits 201902L (C++20) std::is_bounded_array, std::is_unbounded_array

예제

#include <iostream>
#include <type_traits>

#define OUT(...) std::cout << #__VA_ARGS__ << " : " << __VA_ARGS__ << '\n'

class A {};

int main()
{
    std::cout << std::boolalpha;
    OUT(std::is_bounded_array_v<A>);
    OUT(std::is_bounded_array_v<A[]>);
    OUT(std::is_bounded_array_v<A[3]>);
    OUT(std::is_bounded_array_v<float>);
    OUT(std::is_bounded_array_v<int>);
    OUT(std::is_bounded_array_v<int[]>);
    OUT(std::is_bounded_array_v<int[3]>);
}

출력:

std::is_bounded_array_v<A> : false
std::is_bounded_array_v<A[]> : false
std::is_bounded_array_v<A[3]> : true
std::is_bounded_array_v<float> : false
std::is_bounded_array_v<int> : false
std::is_bounded_array_v<int[]> : false
std::is_bounded_array_v<int[3]> : true

같이 보기

is_array (C++11) 타입이 배열 타입인지 확인해요 (클래스 템플릿)
is_unbounded_array (C++20) 타입이 경계가 알려지지 않은 배열 타입인지 확인해요 (클래스 템플릿)
extent (C++11) 지정된 차원에서 배열 타입의 크기를 구해요 (클래스 템플릿)
is_bounded_array_type (C++26) 리플렉션이 경계가 알려진 배열 타입을 나타내는지 확인해요 (함수)

더 알아보기 (Learn more)

cppreference