|
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Basic types | |||||||||||||||||||||
| Fixed width integer types(C++11) | |||||||||||||||||||||
| Fixed width floating-point types(C++23) | |||||||||||||||||||||
| |||||||||||||||||||||
| Numeric limits | |||||||||||||||||||||
| C numeric limits interface | |||||||||||||||||||||
| Runtime type information | |||||||||||||||||||||
| |||||||||||||||||||||
| Static constants | ||||
numeric_limits::is_signed | ||||
(C++11) | ||||
| Static member functions | ||||
(C++11) | ||||
| Helper types | ||||
staticconstbool is_signed; | (until C++11) | |
staticconstexprbool is_signed; | (since C++11) | |
The value ofstd::numeric_limits<T>::is_signed istrue for all signed arithmetic typesT andfalse for the unsigned types. This constant is meaningful for all specializations.
T | value ofstd::numeric_limits<T>::is_signed |
| /* non-specialized */ | false |
| bool | false |
| char | implementation-defined |
| signedchar | true |
| unsignedchar | false |
| wchar_t | implementation-defined |
| char8_t(since C++20) | false |
| char16_t(since C++11) | false |
| char32_t(since C++11) | false |
| short | true |
| unsignedshort | false |
| int | true |
| unsignedint | false |
| long | true |
| unsignedlong | false |
| longlong(since C++11) | true |
| unsignedlonglong(since C++11) | false |
| float | true |
| double | true |
| longdouble | true |
#include <iostream>#include <iomanip>#include <limits> template<typename T>struct test{ test(constchar* 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)"};}
Possible output:
bool : unsignedchar : signedwchar_t : signedchar16_t : unsignedchar32_t : unsignedfloat : signednon-specialized : unsigneddecltype(42) : signed
(C++11) | checks if a type is a signed arithmetic type (class template)[edit] |
[static] | identifies integer types (public static member constant)[edit] |
[static] | identifies exact types (public static member constant)[edit] |
[static] | identifies types that represent a finite set of values (public static member constant)[edit] |