Namespaces
Variants

std::numeric_limits<T>:: is_signed

From cppreference.net
Utilities library
static const bool is_signed ;
(C++11 이전)
static constexpr bool is_signed ;
(C++11 이후)

std:: numeric_limits < T > :: is_signed 의 값은 모든 부호 있는 산술 타입 T 에 대해 true 이고, 부호 없는 타입에 대해서는 false 입니다. 이 상수는 모든 특수화에 대해 의미를 가집니다.

표준 특수화

T std:: numeric_limits < T > :: is_signed 의 값
/* non-specialized */ false
bool false
char 구현 정의
signed char true
unsigned char false
wchar_t 구현 정의
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

예제

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

가능한 출력:

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

참고 항목

(C++11)
타입이 부호 있는 산술 타입인지 검사합니다
(클래스 템플릿)
[static]
정수 타입을 식별합니다
(public static member constant)
[static]
정확한 타입을 식별합니다
(public static member constant)
[static]
유한한 값들의 집합을 나타내는 타입을 식별합니다
(public static member constant)