◐ Shell
clean mode source ↗

std::make_signed - cppreference.com

提供: cppreference.com

<tbody> </tbody>

template< class T > struct make_signed;

(C++11以上)

T が整数 (bool を除く) または列挙型であれば、同じ cv 修飾を持つ T に対応する符号付き整数型であるメンバ型 type が提供されます。

そうでなければ、動作は未定義です。

(C++20未満)

そうでなければ、プログラムは ill-formed です。

(C++20以上)

メンバ型

名前 定義
type T に対応する符号付き整数型

ヘルパー型

<tbody> </tbody>

template< class T > using make_signed_t = typename make_signed<T>::type;

(C++14以上)

#include <iostream>
#include <type_traits>

int main() {
    typedef std::make_signed<unsigned char>::type char_type;
    typedef std::make_signed<unsigned int>::type int_type;
    typedef std::make_signed<volatile unsigned long>::type long_type;

    bool ok1 = std::is_same<char_type, signed char>::value;
    bool ok2 = std::is_same<int_type, signed int>::value;
    bool ok3 = std::is_same<long_type, volatile signed long>::value;

    std::cout << std::boolalpha
    << "char_type is 'signed char'?          : " << ok1 << '\n'
    << "int_type  is 'signed int'?           : " << ok2 << '\n'
    << "long_type is 'volatile signed long'? : " << ok3 << '\n';
}

出力:

char_type is 'signed char'?          : true
int_type  is 'signed int'?           : true
long_type is 'volatile signed long'? : true

関連項目