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
Definiert im Header <type_traits>
template < class T >
struct is_floating_point ;
(seit C++11)

std::is_floating_point ist ein UnaryTypeTrait .

Prüft, ob T ein Gleitkommatyp ist. Stellt die Memberkonstante value bereit, die gleich true ist, falls T der Typ float , double , long double oder erweiterte Gleitkommatypen ( std:: float16_t , std:: float32_t , std:: float64_t , std:: float128_t oder std:: bfloat16_t ) sind (seit C++23) , einschließlich aller cv-qualifizierten Varianten. Andernfalls ist value gleich false .

Wenn das Programm Spezialisierungen für std::is_floating_point oder std::is_floating_point_v hinzufügt, ist das Verhalten undefiniert.

Inhaltsverzeichnis

Template-Parameter

T - ein zu prüfender Typ

Hilfsvariablen-Template

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

Geerbt von std:: integral_constant

Member-Konstanten

value
[static]
true falls T ein Gleitkommatyp ist (möglicherweise cv-qualifiziert), false andernfalls
(öffentliche statische Member-Konstante)

Member-Funktionen

operator bool
konvertiert das Objekt zu bool , gibt value zurück
(öffentliche Member-Funktion)
operator()
(C++14)
gibt value zurück
(öffentliche Member-Funktion)

Member-Typen

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

Mögliche Implementierung

template<class T>
struct is_floating_point
     : std::integral_constant<
         bool,
         // Hinweis: Standard-Gleitkommatypen
         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
         // Hinweis: Erweiterte Gleitkommatypen (C++23, falls unterstützt)
         || 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
     > {};

Beispiel

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

Siehe auch

[static]
identifiziert die IEC 559/IEEE 754 Gleitkommatypen
(öffentliche statische Elementkonstante von std::numeric_limits<T> )
prüft, ob ein Typ ein ganzzahliger Typ ist
(Klassentemplate)
prüft, ob ein Typ ein arithmetischer Typ ist
(Klassentemplate)
spezifiziert, dass ein Typ ein Gleitkommatyp ist
(Konzept)