![]() |
Arene Base
Fundamental Utilities For Safety Critical C++
|
arene::base::byte is a backport of std::byte from C++17. It has the same aliasing properties as std::byte, char and unsigned char, so is ideal for use as backing storage for pre-allocated buffers for objects constructed at runtime, and for buffers for data read from a file or sent across the network.
Just as for std::byte, arene::base::byte does not provide arithmetic operations, but does provide bitwise operators.
The specifications for std::byte is available on cppreference.
The public header is
The Bazel target is
Conversion to arene::base::byte from an integer type can be accomplished via arene::base::to_byte. This API does not do any form of bounds checking, it is equivalent to static_cast'ing the value to an unsigned char.
Conversion from arene::base::byte to an integer type can be accomplished via arene::base::to_integer. This is a backport of std::to_integer, whose specification is available on cppreference.
_byte LiteralTo assist with constructing arene::base::byte values from literals in a C++14 context, a User Defined Literal is provided, arene::base::literals::_byte. This allows direct construction of a byte, like so:
This can be particularly helpful in unit tests when predefined byte values are needed. The _byte literal does not perform any bounds checking on the literal value; it is equivalent to calling arene::base::to_byte on the literal value.