◐ Shell
clean mode source ↗

std::make_unsigned - cppreference.com

来自cppreference.com

template< class T >
struct make_unsigned;
(C++11 起)

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

T 为有符号或无符号的 charshortintlonglong long,则提供此列表中的 T 的对应无符号类型。

T 为枚举类型或 charwchar_­tchar8_­t(C++20 起)char16_­tchar32_­t,则提供与 T 有相同 sizeof 的有最小等级的无符号整数类型。

否则,行为未定义。

(C++20 前)

否则,程序非良构。

(C++20 起)

如果程序添加了 std::make_unsigned 的特化,那么行为未定义。

成员类型

辅助类型

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

示例

#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>
    );
}

参阅