std::is_integral
Defined in header <type_traits> | | |
|---|---|---|
template< class T > struct is_integral; | | (since C++11) |
检查是否T是一个整体类型。提供成员常量。value等于true,如果T类型bool,,,char,,,char16_t,,,char32_t,,,wchar_t,,,short,,,int,,,long,,,long long,或任何实现定义的扩展整数类型,包括任何有符号、无符号和cv限定的变体。否则,value等于false...
模板参数
T | - | a type to check |
|---|
辅助变量模板
template< class T > inline constexpr bool is_integral_v = is_integral<T>::value; | | (since C++17) |
|---|
继承自STD:积分[医]常量
成员常数
value static | true if T is an integral 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> |
例
二次
#include <iostream>
#include <type_traits>
class A {};
template <class T>
T f(T i)
{
static_assert(std::is_integral<T>::value, "Integer required.");
return i;
}
int main()
{
std::cout << std::boolalpha;
std::cout << std::is_integral<A>::value << '\n';
std::cout << std::is_integral<float>::value << '\n';
std::cout << std::is_integral<int>::value << '\n';
std::cout << f(123) << '\n';
}二次
产出:
二次
false
false
true
123二次
另见
is_integer static | identifies integer types (public static member constant of std::numeric_limits) |
|---|---|
is_floating_point (C++11) | checks if a type is floating-point type (class template) |
is_arithmetic (C++11) | checks if a type is arithmetic type (class template) |
© cppreference.com在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com

