首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::is_arithmetic

Defined in header <type_traits>

template< class T > struct is_arithmetic;

(since C++11)

如果T是算术类型%28,即整数类型或浮点类型%29,提供成员常量。value平等true.对于任何其他类型,valuefalse...

模板参数

T

-

a type to check

辅助变量模板

template< class T > inline constexpr bool is_arithmetic_v = is_arithmetic<T>::value;

(since C++17)

继承自STD:积分[医]常量

成员常数

value static

true if T is an arithmetic type , false otherwise (public static member constant)

成员函数

operator bool

converts the object to bool, returns value (public member function)

operator() (C++14)

returns value (public member function)

成员类型

Type

Definition

value_type

bool

type

std::integral_constant<bool, value>

注记

算术类型是内置的类型。算术算子%28+,-,%2A,/%29定义为%28,可能与通常的算术转换%29相结合。

专门性std::numeric_limits为所有算术类型提供。

可能的实施

模板<class T>结构是[医]算术:std::[医]常数<bool,std::is[医]积分<T>*价值STD::是[医]浮[医]点<T>*价值>{};

*。

二次

代码语言:javascript
复制
#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';
}

二次

产出:

二次

代码语言:javascript
复制
A:           false
bool:        true
int:         true
int const:   true
int &:       false
int *:       false
float:       true
float const: true
float &:     false
float *:     false

二次

另见

is_integral (C++11)

checks if a type is integral type (class template)

is_floating_point (C++11)

checks if a type is floating-point type (class template)

代码语言:txt
复制
 © cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券