std::numeric_limits<T>:: is_signed
From cppreference.net
<
cpp
|
types
|
numeric limits
|
static
const
bool
is_signed
;
|
(hasta C++11) | |
|
static
constexpr
bool
is_signed
;
|
(desde C++11) | |
El valor de
std::
numeric_limits
<
T
>
::
is_signed
es
true
para todos los tipos aritméticos con signo
T
y
false
para los tipos sin signo. Esta constante es significativa para todas las especializaciones.
Especializaciones estándar
T
|
valor de std:: numeric_limits < T > :: is_signed |
| /* no especializado */ | false |
| bool | false |
| char | definido por la implementación |
| signed char | true |
| unsigned char | false |
| wchar_t | definido por la implementación |
| char8_t (desde C++20) | false |
| char16_t (desde C++11) | false |
| char32_t (desde C++11) | false |
| short | true |
| unsigned short | false |
| int | true |
| unsigned int | false |
| long | true |
| unsigned long | false |
| long long (desde C++11) | true |
| unsigned long long (desde C++11) | false |
| float | true |
| double | true |
| long double | true |
Ejemplo
Ejecutar este código
#include <iostream> #include <iomanip> #include <limits> template<typename T> struct test { test(const char* name, int w = 15) { std::cout << std::left << std::setw(w) << (std::numeric_limits<T>::is_specialized ? name : "non-specialized") << " : " << (std::numeric_limits<T>::is_signed ? "" : "un") << "signed\n"; } }; int main() { test<bool>{"bool"}; test<char>{"char"}; test<wchar_t>{"wchar_t"}; test<char16_t>{"char16_t"}; test<char32_t>{"char32_t"}; test<float>{"float"}; struct delusion{}; test<delusion>{"delusion"}; test<decltype(42)>{"decltype(42)"}; }
Salida posible:
bool : unsigned char : signed wchar_t : signed char16_t : unsigned char32_t : unsigned float : signed non-specialized : unsigned decltype(42) : signed
Véase también
|
(C++11)
|
comprueba si un tipo es un tipo aritmético con signo
(plantilla de clase) |
|
[static]
|
identifica tipos enteros
(constante de miembro estática pública) |
|
[static]
|
identifica tipos exactos
(constante de miembro estática pública) |
|
[static]
|
identifica tipos que representan un conjunto finito de valores
(constante de miembro estática pública) |