std:: floating_point
From cppreference.net
|
Défini dans l'en-tête
<concepts>
|
||
|
template
<
class
T
>
concept floating_point = std:: is_floating_point_v < T > ; |
(depuis C++20) | |
Le concept
floating_point
<
T
>
est satisfait si et seulement si
T
est un type à virgule flottante.
Exemple
Exécuter ce code
#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'; }
Sortie :
2.2 4.4 888
Références
- Norme C++23 (ISO/CEI 14882:2024) :
-
- 18.4.7 Concepts arithmétiques [concepts.arithmetic]
- Norme C++20 (ISO/CEI 14882:2020) :
-
- 18.4.7 Concepts arithmétiques [concepts.arithmetic]
Voir aussi
|
(C++11)
|
vérifie si un type est un type à virgule flottante
(modèle de classe) |