std::make_unsigned
来自 cppreference.cn
定义于头文件 <type_traits> |
||
template< class T > struct make_unsigned; |
(since C++11) | |
如果 T
是整型(除了 bool)或枚举类型,则提供成员 typedef type
,它是对应于 T
的无符号整型类型,具有相同的 cv 限定符。
如果 T
是有符号或无符号 char, short, int, long, long long;则提供此列表中对应于 T
的无符号类型。
如果 T
是枚举类型或 char, wchar_t, char8_t(since C++20), char16_t, char32_t;则提供具有与 T
相同 sizeof 的最小秩的无符号整型类型。
否则,行为未定义。 |
(until C++20) |
否则,程序是非良构的。 |
(since C++20) |
如果程序为 std::make_unsigned
添加特化,则行为未定义。
内容 |
[edit] 成员类型
名称 | 定义 |
type
|
对应于 T 的无符号整型类型 |
[edit] 辅助类型
template< class T > using make_unsigned_t = typename make_unsigned<T>::type; |
(since C++14) | |
[edit] 示例
运行此代码
#include <type_traits> int main() { using uchar_type = std::make_unsigned_t<char>; using uint_type = std::make_unsigned_t<int>; using ulong_type = std::make_unsigned_t<volatile long>; static_assert( std::is_same_v<uchar_type, unsigned char> and std::is_same_v<uint_type, unsigned int> and std::is_same_v<ulong_type, volatile unsigned long> ); }
[edit] 参见
(C++11) |
检查类型是否为有符号算术类型 (class template) |
(C++11) |
检查类型是否为无符号算术类型 (class template) |
(C++11) |
获取给定整型类型对应的有符号类型 (class template) |