std:: is_floating_point
| Type traits | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Compile-time rational arithmetic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Compile-time integer sequences | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
(C++14)
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
ヘッダーで定義
<type_traits>
|
||
|
template
<
class
T
>
struct is_floating_point ; |
(C++11以降) | |
std::is_floating_point
は
UnaryTypeTrait
です。
T
が浮動小数点型かどうかを判定する。メンバー定数
value
は、
T
が型
float
、
double
、
long
double
、または任意の拡張浮動小数点型(
std::
float16_t
、
std::
float32_t
、
std::
float64_t
、
std::
float128_t
、または
std::
bfloat16_t
)を含む
(C++23以降)
の場合、
true
に等しい。それ以外の場合、
value
は
false
に等しい。
プログラムが
std::is_floating_point
または
std::is_floating_point_v
に対する特殊化を追加する場合、動作は未定義です。
目次 |
テンプレートパラメータ
| T | - | チェックする型 |
ヘルパー変数テンプレート
|
template
<
class
T
>
constexpr bool is_floating_point_v = is_floating_point < T > :: value ; |
(C++17以降) | |
std::integral_constantから継承
メンバ定数
|
value
[static]
|
true
(
T
が浮動小数点型(cv修飾可能性あり)の場合)、
false
(それ以外の場合)
(公開静的メンバ定数) |
メンバ関数
|
operator bool
|
オブジェクトを
bool
に変換し、
value
を返す
(公開メンバ関数) |
|
operator()
(C++14)
|
value
を返す
(公開メンバ関数) |
メンバ型
| 型 | 定義 |
value_type
|
bool |
type
|
std:: integral_constant < bool , value > |
実装例
template<class T> struct is_floating_point : std::integral_constant< bool, // 注: 標準浮動小数点型 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 // 注: 拡張浮動小数点型 (C++23、サポートされている場合) || 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 > {}; |
例
#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() {}
関連項目
|
[static]
|
IEC 559/IEEE 754 浮動小数点型を識別する
(
std::numeric_limits<T>
の
公開静的メンバ定数)
|
|
(C++11)
|
型が整数型かどうかをチェックする
(クラステンプレート) |
|
(C++11)
|
型が算術型かどうかをチェックする
(クラステンプレート) |
|
(C++20)
|
型が浮動小数点型であることを指定する
(コンセプト) |