std::make_signed
來自 cppreference.com
定義於標頭檔案 <type_traits> |
||
template< class T > struct make_signed; |
(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
大小相同的有符號整型。
否則,行為未定義。 |
(C++20 前) |
否則,程式格式錯誤。 |
(C++20 起) |
若程式為 std::make_signed
新增特化,則行為未定義。
目錄 |
[編輯] 成員型別
名稱 | 定義 |
型別
|
對應於 T 的有符號整型 |
[編輯] 輔助型別
template< class T > using make_signed_t = typename make_signed<T>::type; |
(C++14 起) | |
[編輯] 示例
執行此程式碼
#include <type_traits> enum struct E : unsigned short {}; int main() { using char_type = std::make_signed_t<unsigned char>; using int_type = std::make_signed_t<unsigned int>; using long_type = std::make_signed_t<volatile unsigned long>; using enum_type = std::make_signed_t<E>; static_assert( std::is_same_v<char_type, signed char> and std::is_same_v<int_type, signed int> and std::is_same_v<long_type, volatile signed long> and std::is_same_v<enum_type, signed short> ); }
[編輯] 參閱
(C++11) |
檢查型別是否為有符號算術型別 (類模板) |
(C++11) |
檢查型別是否為無符號算術型別 (類模板) |
(C++11) |
獲取給定整型對應的有符號型別 (類模板) |