std::numeric_limits<T>::is_integer
static const bool is_integer; | (до C++11) | |
static constexpr bool is_integer; | (с C++11) |
Значение std::numeric_limits<T>::is_integer равно true для всех целочисленных типов арифметики T и 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) | проверяет, является ли тип целочисленным типом (шаблон класса) |
|
[статический] | определяет знаковый тип (публичная статическая константа) |
|
[статический] | определяет точный тип (публичная статическая константа) |
|
[статический] | определяет типы, которые представляют конечный набор значений (публичная статическая константа) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/w/cpp/types/numeric_limits/is_integer