MADNESS 0.10.1
units.h
Go to the documentation of this file.
1//
2// Created by Eduard Valeyev on 2/5/24.
3//
4
5#ifndef MADNESS_UNITS_H
6#define MADNESS_UNITS_H
7
8#include <cstddef>
9#include <cstdint>
10
11namespace madness {
12
13namespace units::literals {
14
15constexpr std::size_t operator""_KiB(unsigned long long int x) {
16 return 1024ULL * x;
17}
18
19constexpr std::size_t operator""_MiB(unsigned long long int x) {
20 return 1024_KiB * x;
21}
22
23constexpr std::size_t operator""_GiB(unsigned long long int x) {
24 return 1024_MiB * x;
25}
26
27constexpr std::size_t operator""_TiB(unsigned long long int x) {
28 return 1024_GiB * x;
29}
30
31constexpr std::size_t operator""_PiB(unsigned long long int x) {
32 return 1024_TiB * x;
33}
34
35constexpr std::size_t operator""_EiB(unsigned long long int x) {
36 return 1024_PiB * x;
37}
38
39constexpr std::size_t operator""_kB(unsigned long long int x) {
40 return 1024ULL * x;
41}
42
43constexpr std::size_t operator""_KB(unsigned long long int x) {
44 return 1024ULL * x;
45}
46
47constexpr std::size_t operator""_MB(unsigned long long int x) {
48 return 1024_kB * x;
49}
50
51constexpr std::size_t operator""_GB(unsigned long long int x) {
52 return 1024_MB * x;
53}
54
55constexpr std::size_t operator""_TB(unsigned long long int x) {
56 return 1024_GB * x;
57}
58
59constexpr std::size_t operator""_PB(unsigned long long int x) {
60 return 1024_TB * x;
61}
62
63constexpr std::size_t operator""_EB(unsigned long long int x) {
64 return 1024_PB * x;
65}
66
67} // namespace units::literals
68
69/// Unit-aware conversion of a C string to a size_t
70
71/// See https://en.wikipedia.org/wiki/Kilobyte for units. This assumes
72/// memory units throughout, i.e. `MiB` and `MB` both mean 1024*1024 bytes, etc.
73/// To reduce confusion, `KiB`, `kB`, and `KB` all mean 1024 bytes.
74/// @param str The C string to convert.
75/// @return The memory size, in bytes
76std::uint64_t cstr_to_memory_size(const char* str);
77
78} // namespace madness
79
80#endif // MADNESS_UNITS_H
Namespace for all elements and tools of MADNESS.
Definition DFParameters.h:10
std::uint64_t cstr_to_memory_size(const char *str)
Unit-aware conversion of a C string to a size_t.
Definition units.cc:14