Namespaces
Variants

std:: is_arithmetic

From cppreference.net
Metaprogramming library
Type traits
Type categories
(C++11)
(C++11) ( DR* )
(C++11)
(C++11)
is_arithmetic
(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_arithmetic ;
(C++11以降)

std::is_arithmetic UnaryTypeTrait です。

T が算術型(すなわち、整数型または浮動小数点型)またはその cv-qualified 版である場合、メンバー定数 value true に設定します。それ以外の型の場合、 value false となります。

プログラムが std::is_arithmetic または std::is_arithmetic_v (C++17以降) に対する特殊化を追加する場合、動作は未定義です。

目次

テンプレートパラメータ

T - チェックする型

ヘルパー変数テンプレート

template < class T >
constexpr bool is_arithmetic_v = is_arithmetic < T > :: value ;
(C++17以降)

std::integral_constantから継承

メンバ定数

value
[static]
true T が算術型の場合、 false それ以外の場合
(public static member constant)

メンバ関数

operator bool
オブジェクトを bool に変換し、 value を返す
(public member function)
operator()
(C++14)
value を返す
(public member function)

メンバ型

定義
value_type bool
type std:: integral_constant < bool , value >

注記

算術型は、組み込み型のうち 算術演算子 ( + , - , * , / ) が定義されている(通常の算術変換と組み合わせて定義されている場合もある)型を指します。

すべての算術型に対して、 std::numeric_limits の特殊化が提供されています。

実装例

template<class T>
struct is_arithmetic : std::integral_constant<bool,
                                              std::is_integral<T>::value ||
                                              std::is_floating_point<T>::value> {};

#include <atomic>
#include <cstddef>
#include <type_traits>
class A {};
enum class B : int { e };
static_assert(
    std::is_arithmetic_v<bool>            == true  and
    std::is_arithmetic_v<char>            == true  and
    std::is_arithmetic_v<char const>      == true  and
    std::is_arithmetic_v<int>             == true  and
    std::is_arithmetic_v<int const>       == true  and
    std::is_arithmetic_v<float>           == true  and
    std::is_arithmetic_v<float const>     == true  and
    std::is_arithmetic_v<std::size_t>     == true  and
    std::is_arithmetic_v<char&>           == false and
    std::is_arithmetic_v<char*>           == false and
    std::is_arithmetic_v<int&>            == false and
    std::is_arithmetic_v<int*>            == false and
    std::is_arithmetic_v<float&>          == false and
    std::is_arithmetic_v<float*>          == false and
    std::is_arithmetic_v<A>               == false and
    std::is_arithmetic_v<B>               == false and
    std::is_arithmetic_v<decltype(B::e)>  == false and
    std::is_arithmetic_v<std::byte>       == false and
    std::is_arithmetic_v<std::atomic_int> == false
);
int main() {}

関連項目

型が整数型かどうかをチェックする
(クラステンプレート)
型が浮動小数点型かどうかをチェックする
(クラステンプレート)