Namespaces
Variants
Views
Actions

std::numeric_limits<T>::is_signed

From cppreference.com
 
 
Utilities library
General utilities
Date and time
Function objects
Formatting library (C++20)
(C++11)
Relational operators (deprecated in C++20)
Integer comparison functions
(C++20)
Swap and type operations
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
Common vocabulary types
(C++11)
(C++17)
(C++17)
(C++17)
(C++17)

Elementary string conversions
(C++17)
(C++17)
 
Type support
Basic types
Fundamental types
Fixed width integer types (C++11)
Numeric limits
C numeric limits interface
Runtime type information
Type traits
Type categories
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
Type properties
(C++11)
(C++11)
(C++14)
(C++11)
(C++11)(until C++20)
(C++11)(deprecated in C++20)
(C++11)
Type trait constants
Metafunctions
(C++17)
Constant evaluation context
Supported operations
Relationships and property queries
Type modifications
(C++11)(C++11)(C++11)
Type transformations
(C++11)
(C++11)
(C++17)
(C++11)(until C++20)(C++17)
 
 
static const bool is_signed;
(until C++11)
static constexpr bool is_signed;
(since C++11)

The value of std::numeric_limits<T>::is_signed is true for all signed arithmetic types T and false for the unsigned types. This constant is meaningful for all specializations.

[edit] Standard specializations

T value of std::numeric_limits<T>::is_signed
/* non-specialized */ false
bool false
char implementation-defined
signed char true
unsigned char false
wchar_t implementation-defined
char8_t (C++20) false
char16_t (C++11) false
char32_t (C++11) false
short true
unsigned short false
int true
unsigned int false
long true
unsigned long false
long long (C++11) true
unsigned long long (C++11) false
float true
double true
long double true

[edit] Example

#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)"};
}

Possible output:

bool            : unsigned
char            : signed
wchar_t         : signed
char16_t        : unsigned
char32_t        : unsigned
float           : signed
non-specialized : unsigned
decltype(42)    : signed

[edit] See also

(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]