- cstddef[meta header]
- std[meta namespace]
- function template[meta id-type]
- cpp17[meta cpp]
namespace std {
template <class IntType>
constexpr IntType to_integer(byte b) noexcept;
}
byte
型の値を任意の整数型に変換する。
- 型
IntType
は、std::is_integral_v
<IntType> == true
であること。そうでない場合、この関数はオーバーロード解決の候補から除外される
以下の式と等価の効果をもつ:
return IntType(b);
投げない
#include <cassert>
#include <cstddef>
#include <cstdint>
int main()
{
std::byte x{0b0000'1010};
std::uint8_t result_u8 = std::to_integer<std::uint8_t>(x);
assert(result_u8 == 0b0000'1010);
unsigned char result_uc = std::to_integer<unsigned char>(x);
assert(result_uc == 0b0000'1010);
}
- std::to_integer[color ff0000]
- C++17
- Clang, C++17 mode: 5.0
- GCC, C++17 mode: 7.1
- Visual C++: ??