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
Definido en el encabezado <type_traits>
template < class T >
struct is_floating_point ;
(desde C++11)

std::is_floating_point es un UnaryTypeTrait .

Comprueba si T es un tipo de punto flotante. Proporciona la constante miembro value que es igual a true , si T es el tipo float , double , long double , o cualquier tipo de punto flotante extendido ( std:: float16_t , std:: float32_t , std:: float64_t , std:: float128_t , o std:: bfloat16_t ) (since C++23) , incluyendo cualquier variante calificada cv. De lo contrario, value es igual a false .

Si el programa añade especializaciones para std::is_floating_point o std::is_floating_point_v , el comportamiento es indefinido.

Contenidos

Parámetros de plantilla

T - un tipo a verificar

Plantilla de variable auxiliar

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

Heredado de std:: integral_constant

Constantes miembro

value
[static]
true si T es un tipo de punto flotante (posiblemente calificado cv), false en caso contrario
(constante miembro pública estática)

Funciones miembro

operator bool
convierte el objeto a bool , devuelve value
(función miembro pública)
operator()
(C++14)
devuelve value
(función miembro pública)

Tipos miembro

Tipo Definición
value_type bool
type std:: integral_constant < bool , value >

Implementación posible

template<class T>
struct is_floating_point
     : std::integral_constant<
         bool,
         // Nota: tipos estándar de punto flotante
         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
         // Nota: tipos extendidos de punto flotante (C++23, si están soportados)
         || 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
     > {};

Ejemplo

#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() {}

Véase también

[static]
identifica los tipos de punto flotante IEC 559/IEEE 754
(constante de miembro estática pública de std::numeric_limits<T> )
verifica si un tipo es un tipo integral
(plantilla de clase)
verifica si un tipo es un tipo aritmético
(plantilla de clase)
especifica que un tipo es un tipo de punto flotante
(concepto)