Byte Conversions
Description
The library provides functions for converting safe integer types to and from big-endian byte order.
These operate on the non-bounded unsigned types (u8, u16, u32, u64, u128) and their verified counterparts.
On big-endian platforms these are no-ops.
On little-endian platforms they delegate to byteswap.
#include <boost/safe_numbers/byte_conversions.hpp>
to_be
Converts a value from the native byte order to big-endian byte order.
Runtime Overload
template <non_bounded_integral_library_type T>
requires (!is_verified_type_v<T>)
constexpr auto to_be(const T value) noexcept -> T;
Verified Overload
template <non_bounded_integral_library_type T>
consteval auto to_be(const verified_type_basis<T> value) noexcept -> verified_type_basis<T>;
Compile-time only overload for verified types.
Since to_be is consteval for verified types, the result is guaranteed to be a compile-time constant.
from_be
Converts a value from big-endian byte order to the native byte order.
This is the inverse of to_be.
Since byte swapping is its own inverse, from_be delegates directly to to_be.
Runtime Overload
template <non_bounded_integral_library_type T>
requires (!is_verified_type_v<T>)
constexpr auto from_be(const T value) noexcept -> T;
Verified Overload
template <non_bounded_integral_library_type T>
consteval auto from_be(const verified_type_basis<T> value) noexcept -> verified_type_basis<T>;
Compile-time only overload for verified types.
Since from_be is consteval for verified types, the result is guaranteed to be a compile-time constant.