std::is_arithmetic
Материал из cppreference.com
Определено в заголовочном файле <type_traits>
|
||
template< class T > struct is_arithmetic; |
(начиная с C++11) | |
std::is_arithmetic
является UnaryTypeTrait.
Если T
является арифметическим типом (то есть целочисленным типом или типом с плавающей запятой) или его cv-квалифицированной
версией, предоставляет константу-элемент value
равную true. Для любого другого типа value
равна false.
Поведение программы, добавляющей специализации для std::is_arithmetic
или std::is_arithmetic_v
(начиная с C++17) не определено.
Содержание |
[править] Параметры шаблона
T | — | тип для проверки |
[править] Шаблон вспомогательной переменной
template< class T > inline constexpr bool is_arithmetic_v = is_arithmetic<T>::value; |
(начиная с C++17) | |
Унаследован от std::integral_constant
Константы элементы
value [static] |
true, если T это арифметический тип, false иначе (public static константа-элемент) |
Функции-элементы
operator bool |
преобразует объект в bool, возвращает value (public функция-элемент) |
operator() (C++14) |
возвращает value (public функция-элемент) |
Типы элементы
Тип | Определение |
value_type
|
bool |
type
|
std::integral_constant<bool, value> |
[править] Примечание
Арифметическ��е типы это встроенные типы, для которых определены арифметические операторы (+
, -
, *
, /
) (возможно, в сочетании с обычными арифметическими преобразованиями)
Специализации std::numeric_limits предоставляются для всех арифметических типов.
[править] Возможная реализация
template< class T > struct is_arithmetic : std::integral_constant<bool, std::is_integral<T>::value || std::is_floating_point<T>::value> {}; |
[править] Пример
Запустить этот код
#include <atomic> #include <cstddef> #include <type_traits> class A {}; enum class B : int { e }; static_assert( std::is_arithmetic_v<bool> == true and std::is_arithmetic_v<char> == true and std::is_arithmetic_v<char const> == true and std::is_arithmetic_v<int> == true and std::is_arithmetic_v<int const> == true and std::is_arithmetic_v<float> == true and std::is_arithmetic_v<float const> == true and std::is_arithmetic_v<std::size_t> == true and std::is_arithmetic_v<char&> == false and std::is_arithmetic_v<char*> == false and std::is_arithmetic_v<int&> == false and std::is_arithmetic_v<int*> == false and std::is_arithmetic_v<float&> == false and std::is_arithmetic_v<float*> == false and std::is_arithmetic_v<A> == false and std::is_arithmetic_v<B> == false and std::is_arithmetic_v<decltype(B::e)> == false and std::is_arithmetic_v<std::byte> == false and std::is_arithmetic_v<std::atomic_int> == false ); int main() {}
[править] Смотрите также
(C++11) |
проверяет, является ли тип целочисленным типом (шаблон класса) |
(C++11) |
проверяет, является ли тип типом с плавающей запятой (шаблон класса) |