std::make_signed
来自 cppreference.cn
| 定义于头文件 <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) |
获取给定整型对应的有符号类型 (类模板) |