std::numeric_limits<T>:: is_integer
From cppreference.net
<
cpp
|
types
|
numeric limits
C++
Utilities library
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Type support
| Basic types | |||||||||||||||||||||
| Fixed width integer types (C++11) | |||||||||||||||||||||
| Fixed width floating-point types (C++23) | |||||||||||||||||||||
|
|||||||||||||||||||||
| Numeric limits | |||||||||||||||||||||
| C numeric limits interface | |||||||||||||||||||||
| Runtime type information | |||||||||||||||||||||
|
|||||||||||||||||||||
std::numeric_limits
| Static constants | ||||
|
numeric_limits::is_integer
|
||||
|
(C++11)
|
||||
| Static member functions | ||||
|
(C++11)
|
||||
| Helper types | ||||
|
static
const
bool
is_integer
;
|
(C++11 前) | |
|
static
constexpr
bool
is_integer
;
|
(C++11 起) | |
对于所有整数算术类型
T
,
std::
numeric_limits
<
T
>
::
is_integer
的值为
true
,否则为
false
。该常量对所有特化版本均有意义。
标准特化
T
|
std:: numeric_limits < T > :: is_integer 的值 |
| /* non-specialized */ | false |
| bool | true |
| char | true |
| signed char | true |
| unsigned char | true |
| wchar_t | true |
| char8_t (自 C++20 起) | true |
| char16_t (自 C++11 起) | true |
| char32_t (自 C++11 起) | true |
| short | true |
| unsigned short | true |
| int | true |
| unsigned int | true |
| long | true |
| unsigned long | true |
| long long (自 C++11 起) | true |
| unsigned long long (自 C++11 起) | true |
| float | false |
| double | false |
| long double | false |
示例
运行此代码
#include <cstddef> #include <cstdint> #include <limits> static_assert ( std::numeric_limits<bool>::is_integer && std::numeric_limits<std::size_t>::is_integer && std::numeric_limits<std::int32_t>::is_integer && std::numeric_limits<std::int64_t>::is_integer && std::numeric_limits<decltype(42)>::is_integer && !std::numeric_limits<int*>::is_integer && !std::numeric_limits<float>::is_integer && !std::numeric_limits<double>::is_integer && !std::numeric_limits<long double>::is_integer && !std::numeric_limits<decltype([](){})>::is_integer // P0315R4 ); int main() {}
参见
|
(C++11)
|
检查类型是否为整型
(类模板) |
|
[static]
|
标识有符号类型
(公开静态成员常量) |
|
[static]
|
标识精确类型
(公开静态成员常量) |
|
[static]
|
标识表示有限值集的类型
(公开静态成员常量) |