libnick 2025.3.0
A cross-platform base for native Nickvision applications.
Loading...
Searching...
No Matches
sizehelpers.h
Go to the documentation of this file.
1#ifndef SIZEHELPERS_H
2#define SIZEHELPERS_H
3
4#include <type_traits>
5
6#define FACTOR 1024
7
9{
10 template<typename T>
11 concept Numeric = std::is_arithmetic_v<T>;
12
13 template<Numeric T>
14 constexpr T bytesToKilobytes(const T value)
15 {
16 return value / FACTOR;
17 }
18
19 template<Numeric T>
20 constexpr T kilobytesToBytes(const T value)
21 {
22 return value * FACTOR;
23 }
24
25 template<Numeric T>
26 constexpr T bytesToMegabytes(const T value)
27 {
28 return value / (FACTOR * FACTOR);
29 }
30
31 template<Numeric T>
32 constexpr T megabytesToBytes(const T value)
33 {
34 return value * (FACTOR * FACTOR);
35 }
36
37 template<Numeric T>
38 constexpr T bytesToGigabytes(const T value)
39 {
40 return value / (FACTOR * FACTOR * FACTOR);
41 }
42
43 template<Numeric T>
44 constexpr T gigabytesToBytes(const T value)
45 {
46 return value * (FACTOR * FACTOR * FACTOR);
47 }
48}
49
50#endif //SIZEHELPERS_H
Definition sizehelpers.h:9
constexpr T bytesToGigabytes(const T value)
Definition sizehelpers.h:38
constexpr T megabytesToBytes(const T value)
Definition sizehelpers.h:32
constexpr T bytesToMegabytes(const T value)
Definition sizehelpers.h:26
constexpr T gigabytesToBytes(const T value)
Definition sizehelpers.h:44
constexpr T kilobytesToBytes(const T value)
Definition sizehelpers.h:20
constexpr T bytesToKilobytes(const T value)
Definition sizehelpers.h:14