std:: floating_point
Von cppreference.com
| Definiert in der Header-Datei <concepts> |
||
| template< class T > Konzept floating_point = std::is_floating_point_v<T>; |
(seit C++20) | |
Das Konzept floating_point<T> ist genau dann erfüllt, wenn T ein Gleitkommatyp ist.
[bearbeiten] Beispiel
Führen Sie diesen Code aus
#include <concepts> #include <iostream> #include <type_traits> constexpr std::floating_point auto x2(std::floating_point auto x) { return x + x; } constexpr std::integral auto x2(std::integral auto x) { return x << 1; } int main() { constexpr auto d = x2(1.1); static_assert(std::is_same_v<double const, decltype(d)>); std::cout << d << '\n'; constexpr auto f = x2(2.2f); static_assert(std::is_same_v<float const, decltype(f)>); std::cout << f << '\n'; constexpr auto i = x2(444); static_assert(std::is_same_v<int const, decltype(i)>); std::cout << i << '\n'; }
Ausgabe
2.2 4.4 888
[bearbeiten] Referenzen
- C++23 Standard (ISO/IEC 14882:2024)
- 18.4.7 Arithmetische Konzepte [concepts.arithmetic]
- C++20 Standard (ISO/IEC 14882:2020)
- 18.4.7 Arithmetische Konzepte [concepts.arithmetic]
[bearbeiten] Siehe auch
| (C++11) |
prüft, ob ein Typ ein Fließkommatyp ist (Klassenvorlage) |