◐ Shell
clean mode source ↗

std::byte - cppreference.com

提供: cppreference.com

<tbody> </tbody>

enum class byte : unsigned char {} ;

(C++17以上)

std::byte は C++ 言語定義で規定されているバイトの概念を実装する独立した型です。

charunsigned char と同様、他のオブジェクトによって占められている生のメモリ (オブジェクト表現) へのアクセスに使用できます。 しかしそれらの型と異なり、文字型ではなく、算術型でもありません。 バイトは単なるビットのコレクションであり、定義される演算子はビット演算のみです。

非メンバ関数

std::to_integer

<tbody> </tbody>

template <class IntegerType> constexpr IntegerType to_integer(std::byte b) noexcept;

(C++17以上)

return IntegerType(b); と同等です。 このオーバーロードは、std::is_integral_v<IntegerType> が true である場合にのみ、オーバーロード解決に参加します。

std::operator<<=,operator>>=

<tbody> </tbody>

template <class IntegerType> constexpr std::byte& operator<<=(std::byte& b, IntegerType shift) noexcept;

(1) (C++17以上)

template <class IntegerType> constexpr std::byte& operator>>=(std::byte& b, IntegerType shift) noexcept;

(2) (C++17以上)

1) return b = b << shift; と同等です。 このオーバーロードは、std::is_integral_v<IntegerType> が true である場合にのみ、オーバーロード解決に参加します。

2) return b = b >> shift; と同等です。

このオーバーロードは、std::is_integral_v<IntegerType> が true である場合にのみ、オーバーロード解決に参加します。

std::operator<<,operator>>

<tbody> </tbody>

template <class IntegerType> constexpr std::byte operator <<(std::byte b, IntegerType shift) noexcept;

(1) (C++17以上)

template <class IntegerType> constexpr std::byte operator >>(std::byte b, IntegerType shift) noexcept;

(2) (C++17以上)

1) return std::byte(static_cast<unsigned int>(b) << shift); と同等です。 このオーバーロードは、std::is_integral_v<IntegerType> が true である場合にのみ、オーバーロード解決に参加します。

2) return std::byte(static_cast<unsigned int>(b) >> shift); と同等です。

このオーバーロードは、std::is_integral_v<IntegerType> が true である場合にのみ、オーバーロード解決に参加します。

std::operator|=,operator&=,operator^=

<tbody> </tbody>

constexpr std::byte& operator|=(std::byte& l, std::byte r) noexcept;

(1) (C++17以上)

constexpr std::byte& operator&=(std::byte& l, std::byte r) noexcept;

(2) (C++17以上)

constexpr std::byte& operator^=(std::byte& l, std::byte r) noexcept;

(3) (C++17以上)

1) return l = l | r; と同等です。

2) return l = l & r; と同等です。

3) return l = l ^ r; と同等です。

std::operator|,operator&,operator^,operator~

<tbody> </tbody>

constexpr std::byte operator|(std::byte l, std::byte r) noexcept;

(1) (C++17以上)

constexpr std::byte operator&(std::byte l, std::byte r) noexcept;

(2) (C++17以上)

constexpr std::byte operator^(std::byte l, std::byte r) noexcept;

(3) (C++17以上)

constexpr std::byte operator~(std::byte b) noexcept;

(4) (C++17以上)

1) return std::byte(static_cast<unsigned int>(l) | static_cast<unsigned int>(r)); と同等です。

2) return std::byte(static_cast<unsigned int>(l) & static_cast<unsigned int>(r)); と同等です。

3) return std::byte(static_cast<unsigned int>(l) ^ static_cast<unsigned int>(r)); と同等です。

4) return std::byte(~static_cast<unsigned int>(b)); と同等です。

ノート

C++17 の緩和された enum class 初期化ルールにより、数値 nstd::byte{n} を使用して byte の値に変換できます。

byte は (オブジェクトの整数ハッシュを生成するなどのために) std::to_integer を使用して数値に変換できます。