std::make_unsigned

定义于头文件 <type_traits>
template< class T >
struct make_unsigned;
(C++11 起)

T 是整数(除 bool )或枚举类型,则提供成员 typedef type ,它是对应 T 的拥有相同 cv 限定符的无符号整数类型。对应枚举类型的无符号整数类型是拥有最小级别和与枚举相同的 sizeof 的无符号整数类型。

否则,行为未定义。

目录

成员类型

成员 定义
type 对应 T 的无符号整数类型

帮助类型

template< class T >
using make_unsigned_t = typename make_unsigned<T>::type;
(C++14 起)

示例

#include <iostream>
#include <type_traits>
 
int main() {
    typedef std::make_unsigned<char>::type char_type;
    typedef std::make_unsigned<int>::type int_type;
    typedef std::make_unsigned<volatile long>::type long_type;
 
    bool ok1 = std::is_same<char_type, unsigned char>::value; 
    bool ok2 = std::is_same<int_type, unsigned int>::value;
    bool ok3 = std::is_same<long_type, volatile unsigned long>::value;
 
    std::cout << std::boolalpha
    << "char_type is 'unsigned char'?          : " << ok1 << '\n'
    << "int_type  is 'unsigned int'?           : " << ok2 << '\n'
    << "long_type is 'volatile unsigned long'? : " << ok3 << '\n';
}

输出:

char_type is 'unsigned char'?          : true
int_type  is 'unsigned int'?           : true
long_type is 'volatile unsigned long'? : true

参阅

(C++11)
检查类型是否为有符号算术类型
(类模板)
(C++11)
检查类型是否为无符号算术类型
(类模板)
(C++11)
将整数类型转换成对应的有符号整数类型
(类模板)

版本历史

  • (当前 | 先前 2017年7月15日 (六) 20:57Fruderica讨论 | 贡献. . (1,891字节) (-143). . (撤销)
  • 当前 | 先前 2014年10月26日 (日) 18:16P12bot讨论 | 贡献 . . (2,034字节) (0). . (Fix some translations) (撤销)
  • 当前 | 先前 2013年7月2日 (二) 11:43P12bot讨论 | 贡献 . . (2,034字节) (-124). . (Use {{lc}}. Update links. Various fixes.) (撤销)
  • 当前 | 先前 2012年11月2日 (五) 15:46P12bot讨论 | 贡献 . . (2,158字节) (+249). . (r2.7.3) (机器人添加:de, en, es, fr, it, ja, pt, ru) (撤销)
  • 当前 | 先前 2012年10月27日 (六) 11:50P12讨论 | 贡献 . . (1,909字节) (0). . (1个修订: Translate from the English version) (撤销)
  • 当前 | 先前 2012年10月26日 (五) 06:00TranslationBot讨论 | 贡献. . (1,909字节) (-38). . (Translated from the English version using Google Translate) (撤销)
  • 当前 | 先前 2012年10月26日 (五) 03:34P12讨论 | 贡献 . . (1,947字节) (0). . (1个修订: Translate from the English version) (撤销)
  • 当前 | 先前) 2012年10月25日 (四) 12:00TranslationBot讨论 | 贡献. . (1,947字节) (+1,947). . (Translated from the English version using Google Translate)