名稱空間
變體
操作

std::make_unsigned

來自 cppreference.com
< cpp‎ | 型別
 
 
超程式設計庫
型別特性
型別類別
(C++11)
(C++11)(DR*)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11) 
(C++11)
(C++11)
型別屬性
(C++11)
(C++11)
(C++14)
(C++11)(C++26 中已棄用)
(C++11)(直到 C++20*)
(C++11)(C++20 中已棄用)
(C++11)
型別特性常量
元函式
(C++17)
支援的操作
關係與屬性查詢
型別修改
(C++11)(C++11)(C++11)
make_unsigned
(C++11)
型別轉換
(C++11)(C++23 中已棄用)
(C++11)(C++23 中已棄用)
(C++11)
(C++11)(直到 C++20*)(C++17)

(C++11)
(C++17)
編譯時有理數算術
編譯時整數序列
 
定義於標頭檔案 <type_traits>
template< class T >
struct make_unsigned;
(C++11 起)

T 是整型(除了 bool)或列舉型別,則提供成員 typedef type,它是與 T 對應的無符號整型,具有相同的 cv 限定符。

T 是有符號或無符號的 charshortintlonglong long;則提供與 T 對應的此列表中的無符號型別。

T 是列舉型別或 charwchar_tchar8_t(C++20 起)char16_tchar32_t;則提供與 T 具有相同 sizeof 的最小的無符號整型。

否則,行為未定義。

(C++20 前)

否則,程式格式錯誤。

(C++20 起)

若程式為 std::make_unsigned 新增特化,則行為未定義。

目錄

[編輯] 成員型別

名稱 定義
型別 T 對應的無符號整型

[編輯] 輔助型別

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

[編輯] 參閱

(C++11)
檢查型別是否為有符號算術型別
(類模板) [編輯]
檢查型別是否為無符號算術型別
(類模板) [編輯]
獲取給定整型對應的有符號型別
(類模板) [編輯]