types_is_floating_point

types_is_floating_point (부동소수점 타입 판별)

std::is_floating_point는 주어진 타입 T가 부동소수점 타입인지 여부를 컴파일 타임에 판별하는 타입 특성(type trait)이에요. 이 페이지에서는 이 타입 특성의 정의와 사용법, 예제를 확인할 수 있어요.

출처: cppreference

본문

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

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

std::is_floating_point는 UnaryTypeTrait예요.

T가 부동소수점 타입인지 확인해요. Tfloat, double, long double, 또는 확장 부동소수점 타입(std::float16_t, std::float32_t, std::float64_t, std::float128_t, std::bfloat16_t) (C++23부터) 중 하나라면, cv 한정 변형을 포함하여 멤버 상수 valuetrue가 돼요. 그 외의 경우 valuefalse예요.

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

템플릿 매개변수

T - 확인할 타입

헬퍼 변수 템플릿

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

std::integral_constant에서 상속됨

멤버 상수

value [static] T가 부동소수점 타입(possibly cv-qualified)이면 true, 아니면 false (public static member constant)

멤버 함수

operator bool 객체를 bool로 변환하고 value를 반환해요 (public member function)
operator() (C++14) value를 반환해요 (public member function)

멤버 타입

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

가능한 구현

template < class T > struct is_floating_point : std :: integral_constant < bool ,
// Note: standard floating-point types
std :: is_same < float , typename std :: remove_cv < T >:: type >:: value ||
std :: is_same < double , typename std :: remove_cv < T >:: type >:: value ||
std :: is_same < long double , typename std :: remove_cv < T >:: type >:: value
// Note: extended floating-point types (C++23, if supported)
|| std :: is_same < std :: float16_t , typename std :: remove_cv < T >:: type >:: value ||
std :: is_same < std :: float32_t , typename std :: remove_cv < T >:: type >:: value ||
std :: is_same < std :: float64_t , typename std :: remove_cv < T >:: type >:: value ||
std :: is_same < std :: float128_t , typename std :: remove_cv < T >:: type >:: value ||
std :: is_same < std :: bfloat16_t , typename std :: remove_cv < T >:: type >:: value > {};

예제

#include <type_traits>

class A {};
static_assert(!std::is_floating_point_v<A>);

static_assert(std::is_floating_point_v<float>);
static_assert(!std::is_floating_point_v<float&>);
static_assert(std::is_floating_point_v<double>);
static_assert(!std::is_floating_point_v<double&>);
static_assert(!std::is_floating_point_v<int>);

int main() {}

같이 보기

is_iec559 [static] IEC 559/IEEE 754 부동소수점 타입을 식별해요 (std::numeric_limits의 public static member constant) [edit]
is_integral (C++11) 타입이 정수 타입인지 확인해요 (class template) [edit]
is_arithmetic (C++11) 타입이 산술 타입인지 확인해요 (class template) [edit]
floating_point (C++20) 타입이 부동소수점 타입임을 명시해요 (concept) [edit]
is_floating_point_type (C++26) 반영된 타입이 부동소수점 타입인지 확인해요 (function) [edit]

더 알아보기 (Learn more)

cppreference