Foundation
Loading...
Searching...
No Matches
Format.hpp
Go to the documentation of this file.
1#pragma once
2#include <bit>
3#include <Core/Container.hpp>
4#include <fmt/format.h>
5namespace Foundation::Bits {
6 using namespace Foundation::Core;
7 constexpr const char* kSuffixes[]{ "B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" };
8 consteval size_t operator"" _B(unsigned long long k) { return k;}
9 consteval size_t operator"" _KB(unsigned long long k) { return k * (1 << 10LL);}
10 consteval size_t operator"" _MB(unsigned long long k) { return k * (1 << 20LL);}
11 consteval size_t operator"" _GB(unsigned long long k) { return k * (1 << 30LL);}
13 {
14 const int bits = 63 - std::countl_zero(size);
15 const int index = std::min(bits / 10, static_cast<int>(std::size(kSuffixes) - 1));
16 double value = static_cast<double>(size) / (1LL << (index * 10));
17 return fmt::format("{:.2f} {}", value, kSuffixes[index]);
18 }
19}
Header-only convenience utilities.
Definition Chrono.hpp:3
String formatHumanReadableSize(const uint64_t size)
Definition Format.hpp:12
constexpr const char * kSuffixes[]
Definition Format.hpp:7
Allocators, Data Structures and introspection implementations.
Definition Allocator.hpp:5
std::basic_string< char > String
Alias for std::basic_string<char>, without an explicit allocator constructor.
Definition Container.hpp:141
std::unique_ptr< T, StlDeleter< T > > UniquePtr
std::unique_ptr with custom deleter that uses a Foundation::Core::Allocator to deallocate memory.
Definition Allocator.hpp:161