名稱空間
變體
操作

std::make_signed

來自 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_signed
(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_signed;
(C++11 起)

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

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

T 是列舉型別或 charwchar_tchar8_t(C++20 起)char16_tchar32_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)
檢查型別是否為有符號算術型別
(類模板) [編輯]
檢查型別是否為無符號算術型別
(類模板) [編輯]
獲取給定整型對應的有符號型別
(類模板) [編輯]