std::make_signed
来自cppreference.com
                    
                                        
                    
                    
                                                            
                    |   定义于头文件  <type_traits>
  | 
||
|   template< class T > struct make_signed;  | 
(C++11 起) | |
若 T 是整数(除 bool )或枚举类型,则提供是对应 T 的有符号整数类型的成员 typedef type ,它拥有相同的 cv 限定符。
若 T 为有符号或无符号的 char 、 short 、 int 、 long 、 long long ;则提供来自此列表的对应 T 的有符号类型。
若 T 为枚举类型或 char 、 wchar_t 、 char8_t  (C++20 起)、 char16_t 、 char32_t ;则提供与 T 有相同 sizeof 的有最小等级的有符号整数类型。
| 
 否则,行为未定义。  | 
(C++20 前) | 
| 
 否则,程序为非良构。  | 
(C++20 起) | 
添加 make_signed 的特化的程序行为未定义。
成员类型
| 名称 | 定义 | 
  type
 | 
 对应 T 的有符号整数类型
 | 
辅助类型
|   template< class T > using make_signed_t = typename make_signed<T>::type;  | 
(C++14 起) | |
示例
运行此代码
#include <iostream> #include <type_traits> int main() { typedef std::make_signed<char>::type char_type; typedef std::make_signed<int>::type int_type; typedef std::make_signed<volatile long>::type long_type; bool ok1 = std::is_same<char_type, signed char>::value; bool ok2 = std::is_same<int_type, signed int>::value; bool ok3 = std::is_same<long_type, volatile signed long>::value; std::cout << std::boolalpha << "char_type is 'signed char'? : " << ok1 << '\n' << "int_type is 'signed int'? : " << ok2 << '\n' << "long_type is 'volatile signed long'? : " << ok3 << '\n'; }
输出:
char_type is 'signed char'? : true int_type is 'signed int'? : true long_type is 'volatile signed long'? : true
参阅
|    (C++11)  | 
  检查类型是否为有符号算术类型  (类模板)  | 
|    (C++11)  | 
  检查类型是否为无符号算术类型  (类模板)  | 
|    (C++11)  | 
  使给定的整型类型无符号   (类模板)  |