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
ヘッダーで定義 <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> の 公開静的メンバ定数)
型が整数型かどうかをチェックする
(クラステンプレート)
型が算術型かどうかをチェックする
(クラステンプレート)
型が浮動小数点型であることを指定する
(コンセプト)