5#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_BYTE_BYTE_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_BYTE_BYTE_HPP_
17#include "arene/base/stdlib_choice/climits.hpp"
18#include "arene/base/stdlib_choice/cstdint.hpp"
19#include "arene/base/stdlib_choice/enable_if.hpp"
20#include "arene/base/stdlib_choice/is_integral.hpp"
21#include "arene/base/stdlib_choice/is_signed.hpp"
45template <typename ValueType, constraints<std::enable_if_t<std::is_integral<ValueType>::value>> =
nullptr>
46constexpr auto to_byte(ValueType
const val)
noexcept ->
byte {
49 return static_cast<byte>(
static_cast<std::uint8_t>(val));
58template <typename IntegerType, constraints<std::enable_if_t<std::is_integral<IntegerType>::value>> =
nullptr>
59constexpr auto to_integer(
byte const val)
noexcept -> IntegerType {
71template <typename IntegerType, constraints<std::enable_if_t<std::is_integral<IntegerType>::value>> =
nullptr>
72constexpr auto operator<<(
byte const val, IntegerType
const shift)
noexcept ->
byte {
86template <typename IntegerType, constraints<std::enable_if_t<std::is_integral<IntegerType>::value>> =
nullptr>
87constexpr auto operator>>(
byte const val, IntegerType
const shift)
noexcept ->
byte {
103constexpr auto operator|(
byte const lhs,
byte const rhs)
noexcept ->
byte {
111constexpr auto operator&(
byte const lhs,
byte const rhs)
noexcept ->
byte {
119constexpr auto operator^(
byte const lhs,
byte const rhs)
noexcept ->
byte {
127constexpr auto operator~(
byte const val)
noexcept ->
byte {
135template <typename IntegerType, constraints<std::enable_if_t<std::is_integral<IntegerType>::value>> =
nullptr>
136constexpr auto operator<<=(
byte& val, IntegerType
const shift)
noexcept ->
byte& {
145template <typename IntegerType, constraints<std::enable_if_t<std::is_integral<IntegerType>::value>> =
nullptr>
146constexpr auto operator>>=(
byte& val, IntegerType
const shift)
noexcept ->
byte& {
155constexpr auto operator|=(
byte& lhs,
byte const rhs)
noexcept ->
byte& {
164constexpr auto operator&=(
byte& lhs,
byte const rhs)
noexcept ->
byte& {
173constexpr auto operator^=(
byte& lhs,
byte const rhs)
noexcept ->
byte& {
188constexpr byte operator""_byte(
unsigned long long int const value)
noexcept {
return to_byte(value); }
static constexpr value_type value
Definition integral_constant.hpp:34
#define ARENE_PRECONDITION(condition)
Check that a precondition holds, and terminate the application if it does not.
Definition contract.hpp:150
#define ARENE_MAY_ALIAS
An alias for the __may_alias__ attribute, or a no-op if the attribute is not supported.
Definition may_alias.hpp:21
Definition accumulate.hpp:37
constexpr auto operator|=(byte &lhs, byte const rhs) noexcept -> byte &
Modify lhs by bit-wise or'ing it with the bits of rhs.
Definition byte.hpp:155
constexpr auto to_underlying(T value) noexcept -> std::underlying_type_t< T >
This replicates a function that went into C++23 called std::to_underlying (https://wg21....
Definition to_underlying.hpp:26
constexpr auto operator&(byte const lhs, byte const rhs) noexcept -> byte
Bit-wise and of the byte representations.
Definition byte.hpp:111
constexpr auto operator|(byte const lhs, byte const rhs) noexcept -> byte
Bit-wise or of the byte representations.
Definition byte.hpp:103
constexpr auto to_byte(ValueType const val) noexcept -> byte
Convert an integer to an arene::base::byte.
Definition byte.hpp:46
constexpr auto operator>>=(byte &val, IntegerType const shift) noexcept -> byte &
Modify val by shifting its bits right by shift.
Definition byte.hpp:146
constexpr auto operator<<(byte const val, IntegerType const shift) noexcept -> byte
Left-shift the bits of val by shift.
Definition byte.hpp:72
constexpr auto operator<<=(byte &val, IntegerType const shift) noexcept -> byte &
Modify val by shifting its bits left by shift.
Definition byte.hpp:136
constexpr auto operator>>(byte const val, IntegerType const shift) noexcept -> byte
Right-shift the bits of val by shift.
Definition byte.hpp:87
constexpr auto operator&=(byte &lhs, byte const rhs) noexcept -> byte &
Modify lhs by bit-wise and'ing it with the bits of rhs.
Definition byte.hpp:164
constexpr auto operator^(byte const lhs, byte const rhs) noexcept -> byte
Bit-wise xor of the byte representations.
Definition byte.hpp:119
enum ARENE_MAY_ALIAS byte
A type that represents a byte of data.
Definition byte.hpp:39
constexpr auto operator~(byte const val) noexcept -> byte
Bit-wise negation of the byte representation.
Definition byte.hpp:127
constexpr auto operator^=(byte &lhs, byte const rhs) noexcept -> byte &
Modify lhs by bit-wise xor'ing it with the bits of rhs.
Definition byte.hpp:173
constexpr auto to_integer(byte const val) noexcept -> IntegerType
convert the byte value to an integral representation.
Definition byte.hpp:59
Definition accumulate.hpp:36
::uint8_t uint8_t
An 8-bit unsigned integer type.
Definition cstdint.hpp:30
::uint32_t uint32_t
A 32-bit unsigned integer type.
Definition cstdint.hpp:41