命名空间
变体
操作

std::make_signed

来自 cppreference.cn
< cpp‎ | types
 
 
元编程库
类型特性
类型类别
(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 相同 sizeof 的最小 的有符号整型。

否则,行为是未定义的。

(直到 C++20)

否则,程序是非良构的。

(始于 C++20)

如果程序为 std::make_signed 添加特化,则行为是未定义的。

内容

[edit] 成员类型

名称 定义
type 对应于 T 的有符号整型

[edit] 辅助类型

template< class T >
using make_signed_t = typename make_signed<T>::type;
(始于 C++14)

[edit] 示例

#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>
    );
}

[edit] 参见

(C++11)
检查类型是否为有符号算术类型
(类模板) [编辑]
检查类型是否为无符号算术类型
(类模板) [编辑]
获取给定整型对应的有符号类型
(类模板) [编辑]