21namespace storage_literals {
23template <
size_t Power>
25 static constexpr size_t power = Power;
30 constexpr operator uint64_t()
const {
return bytes(); }
42constexpr B operator""_B(
unsigned long long v) {
46constexpr KiB operator""_KiB(
unsigned long long v) {
50constexpr MiB operator""_MiB(
unsigned long long v) {
54constexpr GiB operator""_GiB(
unsigned long long v) {
58constexpr TiB operator""_TiB(
unsigned long long v) {
62template <
typename Dest,
typename Src>
64 if (Src::power < Dest::power) {
65 return Dest(src.count() >> (Dest::power - Src::power));
67 if (Src::power > Dest::power) {
68 return Dest(src.count() << (Src::power - Dest::power));
70 return Dest(src.count());
73static_assert(1_B == 1);
74static_assert(1_KiB == 1 << 10);
75static_assert(1_MiB == 1 << 20);
76static_assert(1_GiB == 1 << 30);
77static_assert(1_TiB == 1ULL << 40);
78static_assert(size_cast<KiB>(1_B).count() == 0);
79static_assert(size_cast<KiB>(1024_B).count() == 1);
80static_assert(size_cast<KiB>(1_MiB).count() == 1024);
constexpr Dest size_cast(Src src)
Definition: storage_literals.h:63
Definition: storage_literals.h:24
constexpr uint64_t count() const
Definition: storage_literals.h:29
uint64_t value_
Definition: storage_literals.h:33
constexpr uint64_t bytes() const
Definition: storage_literals.h:28
constexpr Size(uint64_t count)
Definition: storage_literals.h:26
static constexpr size_t power
Definition: storage_literals.h:25