std:: floating_point
From ja.cppreference.net
|
定義先ヘッダ
<concepts>
|
||
|
template
<
class
T
>
concept floating_point = std:: is_floating_point_v < T > ; |
(C++20以降) | |
コンセプト
floating_point
<
T
>
は、
T
が浮動小数点型である場合にのみ満たされます。
例
このコードを実行
#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'; }
出力:
2.2 4.4 888
参考文献
- C++23標準 (ISO/IEC 14882:2024):
-
- 18.4.7 算術コンセプト [concepts.arithmetic]
- C++20標準 (ISO/IEC 14882:2020):
-
- 18.4.7 算術コンセプト [concepts.arithmetic]
関連項目
|
(C++11)
|
型が浮動小数点型かどうかをチェックする
(クラステンプレート) |