Files
Xenia-Canary/src/xenia/base/literals.h
Wunkolo 1a8068b151 [Base] Add user-literals for several memory sizes
Rather than using `n * 1024 * 1024`, this adds a convenient `_MiB`/`_KiB` user-literal to the new `literals.h` header to concisely describe units of memory in a much more readable way. Any other useful literals can be added to this header. These literals exist in the `xe::literals` namespace so they are opt-in, similar to `std::chrono` literals, and require a `using namespace xe::literals` statement to utilize it within the current scope.

I've done a pass through the codebase to replace trivial instances of `1024 * 1024 * ...` expressions being used but avoided anything that added additional casting complexity from `size_t` to `uint32_t` and such to keep this commit concise.
2022-01-02 11:51:31 -06:00

40 lines
1.1 KiB
C++

/**
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2021 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
#ifndef XENIA_BASE_LITERALS_H_
#define XENIA_BASE_LITERALS_H_
#include <cstdint>
namespace xe::literals {
constexpr size_t operator""_KiB(unsigned long long int x) {
return 1024ULL * x;
}
constexpr size_t operator""_MiB(unsigned long long int x) {
return 1024_KiB * x;
}
constexpr size_t operator""_GiB(unsigned long long int x) {
return 1024_MiB * x;
}
constexpr size_t operator""_TiB(unsigned long long int x) {
return 1024_GiB * x;
}
constexpr size_t operator""_PiB(unsigned long long int x) {
return 1024_TiB * x;
}
} // namespace xe::literals
#endif // XENIA_BASE_LITERALS_H_