std:: make_signed
| Type traits | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Compile-time rational arithmetic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Compile-time integer sequences | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
(C++14)
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
定义于头文件
<type_traits>
|
||
|
template
<
class
T
>
struct make_signed ; |
(C++11 起) | |
如果
T
是整型(除
bool
外)或枚举类型,则提供成员类型定义
type
,该类型是对应于
T
的有符号整数类型,并具有相同的 cv 限定符。
如果
T
是 signed 或 unsigned
char
、
short
、
int
、
long
、
long
long
,则提供此列表中与
T
对应的有符号类型。
如果
T
是枚举类型或
char
,
wchar_t
,
char8_t
(since C++20)
,
char16_t
,
char32_t
,则提供具有相同
sizeof
且秩最小的有符号整数类型。
|
否则,行为是未定义的。 |
(until C++20) |
|
否则,程序是非良构的。 |
(since C++20) |
如果程序为
std::make_signed
添加特化,则行为是未定义的。
目录 |
成员类型
| 名称 | 定义 |
type
|
与
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)
|
获取给定整数类型对应的无符号类型
(类模板) |