std::make_unsigned
來自 cppreference.com
定義於標頭檔案 <type_traits> |
||
template< class T > struct make_unsigned; |
(C++11 起) | |
若 T
是整型(除了 bool)或列舉型別,則提供成員 typedef type
,它是與 T
對應的無符號整型,具有相同的 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 起) |
若程式為 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) |
檢查型別是否為有符號算術型別 (類模板) |
(C++11) |
檢查型別是否為無符號算術型別 (類模板) |
(C++11) |
獲取給定整型對應的有符號型別 (類模板) |