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 типом с плавающей запятой. Предоставляет константу-член value , которая равна true , если T является типом float , double , long double , или любыми расширенными типами с плавающей запятой ( std:: float16_t , std:: float32_t , std:: float64_t , std:: float128_t , или std:: bfloat16_t ) (since C++23) , включая любые cv-квалифицированные варианты. В противном случае, 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-квалифицированным), 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> )
проверяет, является ли тип целочисленным типом
(шаблон класса)
проверяет, является ли тип арифметическим типом
(шаблон класса)
указывает, что тип является типом с плавающей запятой
(концепт)