types_make_signed
types_make_signed (부호 있는 정수 타입 얻기)
이 페이지는 C++ 표준 라이브러리의 std::make_signed 타입 특성에 대해 설명해요. 주어진 정수 타입에 대응하는 부호 있는 정수 타입을 제공하는 템플릿이에요. C++11부터 사용할 수 있어요.
출처: cppreference
본문
정의
| Defined in header <type_traits> | ||
|---|---|---|
| template < class T > struct make_signed ; | (since C++11) |
T가 정수 타입(bool 제외) 또는 열거형 타입이라면, T에 대응하는 부호 있는 정수 타입을 동일한 cv 한정자와 함께 제공하는 멤버 typedef type을 제공해요.
T가 signed 또는 unsigned char, short, int, long, long long이라면, 이 목록에서 T에 대응하는 부호 있는 타입이 제공돼요.
T가 열거형 타입 또는 char, wchar_t, char8_t(C++20부터), char16_t, char32_t라면, T와 같은 sizeof를 가지면서 가장 작은 rank를 가진 부호 있는 정수 타입이 제공돼요.
그 외의 경우 동작은 정의되지 않아요. (C++20까지)
그 외의 경우 프로그램은 ill-formed예요. (C++20부터)
프로그램이 std::make_signed에 대해 특수화를 추가하면 동작은 정의되지 않아요.
Member types
| Name | Definition |
|---|---|
| type | T에 대응하는 부호 있는 정수 타입 |
Helper types
| template < class T > using make_signed_t = typename make_signed < T >:: type ; | (since C++14) |
|---|
Example
#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>
);
}
See also
| is_signed (C++11) | 타입이 부호 있는 산술 타입인지 확인해요 (클래스 템플릿) [edit] |
|---|---|
| is_unsigned (C++11) | 타입이 부호 없는 산술 타입인지 확인해요 (클래스 템플릿) [edit] |
| make_unsigned (C++11) | 주어진 정수 타입에 대응하는 부호 없는 타입을 얻어요 (클래스 템플릿) [edit] |
| make_unsigned (C++26) | 반영된 정수 타입에 대응하는 부호 없는 타입을 반환해요 (함수) [edit] |
| make_signed (C++26) | 반영된 정수 타입에 대응하는 부호 있는 타입을 반환해요 (함수) [edit] |