Namespaces
Variants

std:: is_floating_point

From cppreference.net
Metaprogramming library
Type traits
Type categories
(C++11)
(C++11) ( DR* )
(C++11)
(C++11)
is_floating_point
(C++11)
Type properties
(C++11)
(C++11)
(C++14)
(C++11) (deprecated in C++26)
(C++11) ( until C++20* )
(C++11) (deprecated in C++20)
(C++11)
Type trait constants
Metafunctions
(C++17)
Supported operations
Relationships and property queries
Type modifications
Type transformations
(C++11) (deprecated in C++23)
(C++11) (deprecated in C++23)
(C++11)
(C++11) ( until C++20* ) (C++17)

Compile-time rational arithmetic
Compile-time integer sequences
헤더에 정의됨 <type_traits>
template < class T >
struct is_floating_point ;
(C++11부터)

std::is_floating_point UnaryTypeTrait 입니다.

T 가 부동소수점 타입인지 확인합니다. T float , double , long double 타입이거나, 확장 부동소수점 타입 ( std:: float16_t , std:: float32_t , std:: float64_t , std:: float128_t , 또는 std:: bfloat16_t )인 경우 (C++23부터) 를 포함하여 모든 cv-한정 변형인 경우, value 멤버 상수는 true 와 같습니다. 그렇지 않으면 value false 와 같습니다.

프로그램이 std::is_floating_point 또는 std::is_floating_point_v 에 대한 특수화를 추가하는 경우, 그 동작은 정의되지 않습니다.

목차

템플릿 매개변수

T - 확인할 타입

헬퍼 변수 템플릿

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

std:: integral_constant 로부터 상속됨

멤버 상수

value
[static]
true 만약 T 가 부동소수점 타입인 경우 (cv-qualified 가능), false 그 외의 경우
(public static member constant)

멤버 함수

operator bool
객체를 bool 로 변환, value 반환
(public member function)
operator()
(C++14)
value 반환
(public member function)

멤버 타입

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

가능한 구현

template<class T>
struct is_floating_point
     : std::integral_constant<
         bool,
         // 참고: 표준 부동소수점 타입
         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
         // 참고: 확장 부동소수점 타입 (C++23, 지원되는 경우)
         || 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() {}

참고 항목

[static]
IEC 559/IEEE 754 부동소수점 타입을 식별함
( std::numeric_limits<T> 의 public static 멤버 상수)
타입이 정수형 타입인지 검사함
(클래스 템플릿)
타입이 산술 타입인지 검사함
(클래스 템플릿)
타입이 부동소수점 타입임을 명시함
(컨셉트)