std::make_unsigned
提供: cppreference.com
ヘッダ <type_traits> で定義
|
||
template< class T > struct make_unsigned; |
(C++11以上) | |
T
が整数 (bool を除く) または列挙型であれば、同じ cv 修飾を持つ T
に対応する符号なし整数型であるメンバ型 type
が提供されます。 列挙型に対応する符号なし整数型は、その列挙型と sizeof
が同じ最も小さなランクを持つ符号なし整数型です。
そうでなければ、動作は未定義です。 |
(C++20未満) |
そうでなければ、プログラムは ill-formed です。 |
(C++20以上) |
目次 |
[編集] メンバ型
名前 | 定義 |
type
|
T に対応する符号なし整数型
|
[編集] ヘルパー型
template< class T > using make_unsigned_t = typename make_unsigned<T>::type; |
(C++14以上) | |
[編集] 例
Run this code
#include <iostream> #include <type_traits> int main() { typedef std::make_unsigned<char>::type char_type; typedef std::make_unsigned<int>::type int_type; typedef std::make_unsigned<volatile long>::type long_type; bool ok1 = std::is_same<char_type, unsigned char>::value; bool ok2 = std::is_same<int_type, unsigned int>::value; bool ok3 = std::is_same<long_type, volatile unsigned long>::value; std::cout << std::boolalpha << "char_type is 'unsigned char'? : " << ok1 << '\n' << "int_type is 'unsigned int'? : " << ok2 << '\n' << "long_type is 'volatile unsigned long'? : " << ok3 << '\n'; }
出力:
char_type is 'unsigned char'? : true int_type is 'unsigned int'? : true long_type is 'volatile unsigned long'? : true
[編集] 関連項目
(C++11) |
型が符号付き算術型かどうか調べます (クラステンプレート) |
(C++11) |
型が符号なし算術型かどうか調べます (クラステンプレート) |
(C++11) |
指定された整数型を符号付きにします (クラステンプレート) |