Namespaces
Variants

std:: make_signed

From cppreference.net
Metaprogramming library
Type traits
Type categories
(C++11)
(C++11) ( DR* )
Type properties
(C++11)
(C++11)
(C++14)
(C++11) (deprecated in C++26)
(C++11) ( until C++20* )
(C++11) (deprecated in C++20)
(C++11)
Type trait constants
Metafunctions
(C++17)
Supported operations
Relationships and property queries
Type modifications
(C++11) (C++11) (C++11)
make_signed
(C++11)
Type transformations
(C++11) (deprecated in C++23)
(C++11) (deprecated in C++23)
(C++11)
(C++11) ( until C++20* ) (C++17)

Compile-time rational arithmetic
Compile-time integer sequences
헤더 파일에 정의됨 <type_traits>
template < class T >
struct make_signed ;
(C++11부터)

만약 T 가 integral 타입( bool 제외)이나 enumeration 타입인 경우, 동일한 cv-qualifier를 가지며 T 에 해당하는 signed integer 타입인 type 멤버 typedef를 제공합니다.

만약 T 가 signed 또는 unsigned char , short , int , long , long long 인 경우, 이 목록에서 T 에 해당하는 signed 타입이 제공됩니다.

만약 T 가 열거형 타입이거나 char , wchar_t , char8_t (C++20부터) , char16_t , char32_t 인 경우, 동일한 sizeof 를 가지는 가장 작은 순위 의 부호 있는 정수 타입이 제공됩니다.

그 외의 경우, 동작은 정의되지 않는다.

(until C++20)

그 외의 경우, 프로그램은 형식 오류를 가진다.

(since C++20)

프로그램이 std::make_signed 에 대한 특수화를 추가하는 경우, 동작은 정의되지 않습니다.

목차

멤버 타입

이름 정의
type T 에 해당하는 부호 있는 정수형

헬퍼 타입

template < class T >
using make_signed_t = typename make_signed < T > :: type ;
(C++14부터)

예제

#include <type_traits>
enum struct E : unsigned short {};
int main()
{
    using char_type = std::make_signed_t<unsigned char>;
    using int_type  = std::make_signed_t<unsigned int>;
    using long_type = std::make_signed_t<volatile unsigned long>;
    using enum_type = std::make_signed_t<E>;
    static_assert(
        std::is_same_v<char_type, signed char> and
        std::is_same_v<int_type, signed int> and
        std::is_same_v<long_type, volatile signed long> and
        std::is_same_v<enum_type, signed short>
    );
}

참고 항목

(C++11)
타입이 부호 있는 산술 타입인지 검사합니다
(클래스 템플릿)
타입이 부호 없는 산술 타입인지 검사합니다
(클래스 템플릿)
주어진 정수 타입에 해당하는 부호 없는 타입을 얻습니다
(클래스 템플릿)