std::numeric_limits<T>::is_integer
來自 cppreference.com
static const bool is_integer; |
(C++11 前) | |
static constexpr bool is_integer; |
(C++11 起) | |
std::numeric_limits<T>::is_integer 的值為所有整數算術型別 T
返回 true,否則返回 false。此常量對所有特化都是有意義的。
[編輯] 標準特化
T
|
std::numeric_limits<T>::is_integer 的值 |
/* 未特化 */ | 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) |
檢查型別是否為整型 (類模板) |
[靜態] |
確定有符號型別 (公共靜態成員常量) |
[靜態] |
確定精確型別 (公共靜態成員常量) |
[靜態] |
確定表示有限值集合的型別 (公共靜態成員常量) |