/
githubmirror
/
bitcoin
Обзор
Документация
Войти
/
githubmirror
/
bitcoin
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/util/byte_units.h
37 строк
1 KB
MarcoFalke
util: Return uint64_t from _MiB and _GiB operators
24 апр 2026, 17:43
24 апр 2026, 17:43
fa58017
Код
Авторство
О чём код?
// Copyright (c) 2025-present The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #ifndef BITCOIN_UTIL_BYTE_UNITS_H #define BITCOIN_UTIL_BYTE_UNITS_H #include <util/overflow.h> #include <limits> #include <stdexcept> namespace util::detail { template <unsigned SHIFT> consteval uint64_t ByteUnitsToBytes(unsigned long long units) { const auto bytes{CheckedLeftShift(units, SHIFT)}; if (!bytes || *bytes > std::numeric_limits<uint64_t>::max()) { throw std::overflow_error("Too large"); } return *bytes; } } // namespace util::detail /// Conversion of MiB to bytes. consteval uint64_t operator""_MiB(unsigned long long mebibytes) { return util::detail::ByteUnitsToBytes<20>(mebibytes); } /// Conversion of GiB to bytes. consteval uint64_t operator""_GiB(unsigned long long gibibytes) { return util::detail::ByteUnitsToBytes<30>(gibibytes); } #endif // BITCOIN_UTIL_BYTE_UNITS_H