Bitcoin Core
32.99.0
P2P Digital Currency
Loading...
Searching...
No Matches
src
util
byte_units.h
Go to the documentation of this file.
1
// Copyright (c) 2025-present The Bitcoin Core developers
2
// Distributed under the MIT software license, see the accompanying
3
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5
#ifndef BITCOIN_UTIL_BYTE_UNITS_H
6
#define BITCOIN_UTIL_BYTE_UNITS_H
7
8
#include <
util/overflow.h
>
9
10
#include <limits>
11
#include <stdexcept>
12
13
namespace
util::detail
{
14
template
<
unsigned
SHIFT>
15
consteval
uint64_t
ByteUnitsToBytes
(
unsigned
long
long
units
)
16
{
17
const
auto
bytes{
CheckedLeftShift
(
units
,
SHIFT
)};
18
if
(!bytes || *bytes > std::numeric_limits<uint64_t>::max()) {
19
throw
std::overflow_error(
"Too large"
);
20
}
21
return
*bytes;
22
}
23
}
// namespace util::detail
24
26
consteval
uint64_t
operator
""
_MiB
(
unsigned
long
long
mebibytes
)
27
{
28
return
util::detail::ByteUnitsToBytes<20>(
mebibytes
);
29
}
30
32
consteval
uint64_t
operator
""
_GiB
(
unsigned
long
long
gibibytes
)
33
{
34
return
util::detail::ByteUnitsToBytes<30>(
gibibytes
);
35
}
36
37
#endif
// BITCOIN_UTIL_BYTE_UNITS_H
util::detail
Definition
byte_units.h:13
util::detail::ByteUnitsToBytes
consteval uint64_t ByteUnitsToBytes(unsigned long long units)
Definition
byte_units.h:15
overflow.h
CheckedLeftShift
constexpr std::optional< T > CheckedLeftShift(T input, unsigned shift) noexcept
Left bit shift with overflow checking.
Definition
overflow.h:83
Ticks
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.
Definition
time.h:82
Generated on Fri Oct 23 2026 20:00:32 for Bitcoin Core by
1.9.8