std::is_arithmetic
提供: cppreference.com
<tbody>
</tbody>
| ヘッダ <type_traits> で定義
|
||
template< class T > struct is_arithmetic; |
(C++11以上) | |
T が算術型 (つまり整数型か浮動小数点型) またはその cv 修飾された型であれば、 true に等しいメンバ定数 value が提供されます。 それ以外の型に対しては、 value は false です。
テンプレート引数
| T | - | 調べる型 |
ヘルパー変数テンプレート
<tbody> </tbody> template< class T > inline constexpr bool is_arithmetic_v = is_arithmetic<T>::value; |
(C++17以上) | |
std::integral_constant から継承
メンバ定数
value [静的] |
T が算術型ならば true、そうでなければ false (パブリック静的メンバ定数) |
メンバ関数
operator bool |
オブジェクトを bool に変換します。 value を返します (パブリックメンバ関数) |
operator() (C++14) |
value を返します (パブリックメンバ関数) |
メンバ型
| 型 | 定義 |
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> {};
|
例
Run this code
#include <iostream>
#include <type_traits>
class A {};
int main()
{
std::cout << std::boolalpha;
std::cout << "A: " << std::is_arithmetic<A>::value << '\n';
std::cout << "bool: " << std::is_arithmetic<bool>::value << '\n';
std::cout << "int: " << std::is_arithmetic<int>::value << '\n';
std::cout << "int const: " << std::is_arithmetic<int const>::value << '\n';
std::cout << "int &: " << std::is_arithmetic<int&>::value << '\n';
std::cout << "int *: " << std::is_arithmetic<int*>::value << '\n';
std::cout << "float: " << std::is_arithmetic<float>::value << '\n';
std::cout << "float const: " << std::is_arithmetic<float const>::value << '\n';
std::cout << "float &: " << std::is_arithmetic<float&>::value << '\n';
std::cout << "float *: " << std::is_arithmetic<float*>::value << '\n';
std::cout << "char: " << std::is_arithmetic<char>::value << '\n';
std::cout << "char const: " << std::is_arithmetic<char const>::value << '\n';
std::cout << "char &: " << std::is_arithmetic<char&>::value << '\n';
std::cout << "char *: " << std::is_arithmetic<char*>::value << '\n';
}
出力:
A: false
bool: true
int: true
int const: true
int &: false
int *: false
float: true
float const: true
float &: false
float *: false
char: true
char const: true
char &: false
char *: false
関連項目
(C++11) |
型が整数型かどうか調べます (クラステンプレート) |
(C++11) |
型が浮動小数点型かどうか調べます (クラステンプレート) |