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)