5#ifndef BITCOIN_UTIL_BYTE_UNITS_H
6#define BITCOIN_UTIL_BYTE_UNITS_H
14template <
unsigned SHIFT>
18 if (!bytes || *bytes > std::numeric_limits<size_t>::max()) {
19 throw std::overflow_error(exception_msg);
26constexpr size_t operator""_MiB(
unsigned long long mebibytes)
28 return util::detail::ByteUnitsToBytes<20>(mebibytes,
"MiB value too large for size_t byte conversion");
32constexpr size_t operator""_GiB(
unsigned long long gibibytes)
34 return util::detail::ByteUnitsToBytes<30>(gibibytes,
"GiB value too large for size_t byte conversion");
constexpr size_t ByteUnitsToBytes(unsigned long long units, const char *exception_msg)
constexpr std::optional< T > CheckedLeftShift(T input, unsigned shift) noexcept
Left bit shift with overflow checking.