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
Défini dans l'en-tête <type_traits>
template < class T >
struct is_floating_point ;
(depuis C++11)

std::is_floating_point est un UnaryTypeTrait .

Vérifie si T est un type à virgule flottante. Fournit la constante membre value qui est égale à true , si T est le type float , double , long double , ou tout type étendu à virgule flottante ( std:: float16_t , std:: float32_t , std:: float64_t , std:: float128_t , ou std:: bfloat16_t ) (depuis C++23) , y compris toutes les variantes cv-qualifiées. Sinon, value est égale à false .

Si le programme ajoute des spécialisations pour std::is_floating_point ou std::is_floating_point_v , le comportement est indéfini.

Table des matières

Paramètres du modèle

T - un type à vérifier

Modèle de variable d'assistance

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

Hérité de std:: integral_constant

Constantes membres

value
[static]
true si T est un type à virgule flottante (éventuellement qualifié cv), false sinon
(constante membre publique statique)

Fonctions membres

operator bool
convertit l'objet en bool , retourne value
(fonction membre publique)
operator()
(C++14)
retourne value
(fonction membre publique)

Types membres

Type Définition
value_type bool
type std:: integral_constant < bool , value >

Implémentation possible

template<class T>
struct is_floating_point
     : std::integral_constant<
         bool,
         // Note : types à virgule flottante standard
         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 : types à virgule flottante étendus (C++23, si supportés)
         || 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
     > {};

Exemple

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

Voir aussi

[static]
identifie les types à virgule flottante IEC 559/IEEE 754
(constante de membre statique publique de std::numeric_limits<T> )
vérifie si un type est un type entier
(modèle de classe)
vérifie si un type est un type arithmétique
(modèle de classe)
spécifie qu'un type est un type à virgule flottante
(concept)