types_is_fundamental

types_is_fundamental (기본형 타입 판별)

이 페이지에서는 C++ 표준 라이브러리의 std::is_fundamental 타입 특성에 대해 설명해요. 이 템플릿은 주어진 타입 T가 기본형(fundamental type)인지 아닌지를 컴파일 타임에 판별해 줘요. 기본형에는 산술형(arithmetic type), void, std::nullptr_t, 그리고 C++26부터는 std::meta::info가 포함돼요.

출처: cppreference

본문

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

std::is_fundamental은 UnaryTypeTrait이에요. 만약 T가 기본형(즉, 산술형, void, std::nullptr_t, std::meta::info (C++26부터))이라면, 멤버 상수 valuetrue와 같아요. 다른 모든 타입에 대해서는 valuefalse예요. 프로그램이 std::is_fundamental 또는 std::is_fundamental_v에 대한 특수화를 추가하면, 동작이 정의되지 않아요.

템플릿 매개변수

T - 확인할 타입

헬퍼 변수 템플릿

template < class T > constexpr bool is_fundamental_v = is_fundamental < T >:: value ;

(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>

가능한 구현

template < class T > struct is_fundamental : std :: integral_constant < bool , std :: is_arithmetic < T >:: value || std :: is_void < T >:: value || std :: is_same < std :: nullptr_t , typename std :: remove_cv < T >:: type >:: value // you can also use 'std::is_null_pointer<T>::value' instead in C++14 #if __cpp_impl_reflection > 0 || std :: is_reflection_v < T > #endif > {};

예제

#include <type_traits>

static_assert(std::is_fundamental_v<int> == true);
static_assert(std::is_fundamental_v<int&> == false);
static_assert(std::is_fundamental_v<int*> == false);
static_assert(std::is_fundamental_v<void> == true);
static_assert(std::is_fundamental_v<void*> == false);
static_assert(std::is_fundamental_v<float> == true);
static_assert(std::is_fundamental_v<float&> == false);
static_assert(std::is_fundamental_v<float*> == false);
static_assert(std::is_fundamental_v<std::nullptr_t> == true);
static_assert(std::is_fundamental_v<std::is_fundamental<int>> == false);

class A {};
static_assert(std::is_fundamental_v<A> == false);
static_assert(std::is_fundamental_v<std::is_fundamental<A>::value_type>);

int main() {}

같이 보기

is_compound (C++11) 타입이 복합형(compound type)인지 확인해요 (클래스 템플릿)
is_arithmetic (C++11) 타입이 산술형(arithmetic type)인지 확인해요 (클래스 템플릿)
is_void (C++11) 타입이 void인지 확인해요 (클래스 템플릿)
is_null_pointer (C++11) (DR*) 타입이 std::nullptr_t인지 확인해요 (클래스 템플릿)
is_reflection (C++26) 타입이 std::meta::info인지 확인해요 (클래스 템플릿)
is_fundamental_type (C++26) 리플렉션이 기본형을 나타내는지 확인해요 (함수)

더 알아보기 (Learn more)

cppreference