20 constexpr Byte() =
default;
21 explicit(
false)
constexpr Byte(u8 val)
24 explicit(
false)
constexpr Byte(std::byte val)
25 :
Byte{
static_cast<u8
>(val)} {}
32 template <std::
integral Narrowable>
33 requires(!std::same_as<Narrowable, u8>)
34 explicit(
false)
consteval Byte(Narrowable val)
39 template <std::
integral Narrowable>
41 constexpr auto max_val = 255;
43 if (val < 0 || val > max_val) {
44 throw std::out_of_range(
"value is not representable as a byte");
47 return gsl::narrow_cast<u8>(val);
51 explicit constexpr operator u8()
const {
return value; }
54 explicit constexpr operator std::byte()
const {
return std::byte{
value}; }
78#define DEF_BINARY_OP(op) \
79 constexpr Byte operator op(const Byte& rhs) const { return static_cast<u8>(value op rhs.value); }
81#define DEF_BINARY_ASSIGN_OP(op) \
82 constexpr Byte& operator op(const Byte & rhs) { \
110#undef DEF_BINARY_ASSIGN_OP
115static_assert(
sizeof(Byte) == 1);
123 fmt::formatter<UnderlyingT>
f;
125 bool empty_format_spec{};
127 constexpr auto parse(fmt::format_parse_context& ctx) {
129 if (ctx.begin() == ctx.end() || *ctx.begin() ==
'}') {
130 empty_format_spec =
true;
135 constexpr auto format(const ::asmgrader::Byte& from, fmt::format_context& ctx)
const {
136 if (is_debug_format) {
137 ctx.advance_to(fmt::format_to(ctx.out(),
"Byte{{"));
141 if (empty_format_spec) {
142 if (is_debug_format) {
146 ctx.advance_to(fmt::format_to(ctx.out(),
"{:02X}", from.value));
148 ctx.advance_to(f.format(from.value, ctx));
151 if (is_debug_format) {
#define DEF_BINARY_ASSIGN_OP(op)
Definition byte.hpp:81
#define DEF_BINARY_OP(op)
Definition byte.hpp:78
More user-friendly interface wrapper for a byte-like integral.
Definition byte.hpp:18
u8 value
Bitwise or.
Definition byte.hpp:112
static constexpr Byte narrow_from(Narrowable val)
Attempt to perform a narrowing conversion from val to a Byte.
Definition byte.hpp:40
constexpr bool operator==(const Byte &rhs) const =default
Compiler generated equality operator with another Byte
constexpr auto operator<=>(const Byte &rhs) const =default
Compiler generated comparison operators with another Byte
constexpr Byte operator~() const
Unary bitwise not.
Definition byte.hpp:75
Definition asm_buffer.hpp:20