Byte count that is the same width on every host. More...
#include <StormByte/size.hxx>
Public Member Functions | |
Life | |
| constexpr | Size () noexcept |
| Zero. | |
| template<Type::Integral T> | |
| constexpr | Size (T value) noexcept |
| From an integer count. | |
| constexpr | Size (const Size &other) noexcept=default |
| Copy constructor. | |
| constexpr | Size (Size &&other) noexcept=default |
| Move constructor. | |
| constexpr | ~Size () noexcept=default |
| Destructor. | |
| constexpr Size & | operator= (const Size &other) noexcept=default |
| Copy assignment. | |
| constexpr Size & | operator= (Size &&other) noexcept=default |
| Move assignment. | |
| template<Type::Integral T> | |
| constexpr Size & | operator= (T value) noexcept |
| Assign an integer count. | |
Observers | |
| constexpr std::uint64_t | Value () const noexcept |
| Stored count. | |
Conversions | |
| constexpr | operator std::uint64_t () const noexcept |
| Stored count. | |
| template<typename T > requires Type::SameAs<T, std::size_t> && (!Type::SameAs<std::size_t, std::uint64_t>) | |
| constexpr | operator T () const noexcept |
Stored count as host size_t. | |
| constexpr | operator std::ptrdiff_t () const noexcept |
Stored count as ptrdiff_t (non-negative offsets). | |
| operator CString () const noexcept | |
| IEC text owned by StormByte. | |
| operator std::string () const | |
| IEC text in the caller’s heap. | |
Friends | |
Comparison | |
| constexpr bool | operator== (Size lhs, Size rhs) noexcept |
| Numeric equality. | |
| constexpr std::strong_ordering | operator<=> (Size lhs, Size rhs) noexcept |
| Numeric order. | |
Arithmetic | |
| constexpr Size & | operator+= (Size other) noexcept |
Adds other to this size. | |
| constexpr Size & | operator-= (Size other) noexcept |
Subtracts other from this size. | |
| constexpr Size | operator+ (Size lhs, Size rhs) noexcept |
| Sum. | |
| constexpr Size | operator- (Size lhs, Size rhs) noexcept |
| Difference. | |
Byte count that is the same width on every host.
Stored as std::uint64_t. Safe to return across a DLL boundary and between 32-bit and 64-bit modules. Not a replacement for std::size_t inside a single translation unit.
Construction from a non-negative integer is implicit and constexpr: Size s = 0, s = 16, { Status::Ok, 0 }, constexpr Size MinWindow{16ull * 1024ull}. A negative integer is undefined and asserts when assertions are on.
Mixed comparisons and addition/subtraction with integers work on both sides (5 == s, s == 5, 16 + s, s + 16) via hidden friends. There is no implicit conversion to an integer. Value(), explicit operator uint64_t, explicit operator size_t (only when size_t is not uint64_t) and explicit operator ptrdiff_t are the numeric exits. A value that does not fit the target type is undefined and asserts when assertions are on.
Addition, subtraction and unit scale (4 * MiB, s * 4, s / 4, s % 4) are constexpr. Overflow, a negative integer or a zero divisor is undefined and asserts when assertions are on. There is no Size * Size and no floating-point scale of a Size.
Units are IEC (KiB, MiB, …) and SI (KB, MB, …). A fractional factor rounds to the nearest byte.
operator CString and operator std::string are the IEC human-readable form (B, KiB, …). CString is built in the StormByte DLL. std::string is built in the caller’s heap from that CString.
|
inlineconstexprnoexcept |
Zero.
|
inlineconstexprnoexcept |
From an integer count.
| T | Integral type. |
| value | Byte count. |
value is undefined. Checked with assert when assertions are on.
|
constexprdefaultnoexcept |
Copy constructor.
| other | Size to copy. |
|
constexprdefaultnoexcept |
Move constructor.
| other | Size to take. |
|
constexprdefaultnoexcept |
Destructor.
|
explicitnoexcept |
IEC text owned by StormByte.
B, KiB, MiB, GiB, TiB, PiB, EiB).
|
inlineexplicitconstexprnoexcept |
Stored count as ptrdiff_t (non-negative offsets).
std::ptrdiff_t. ptrdiff_t is undefined. Checked with assert when assertions are on.
|
inline |
IEC text in the caller’s heap.
|
inlineexplicitconstexprnoexcept |
Stored count.
uint64_t.
|
inlineexplicitconstexprnoexcept |
Stored count as host size_t.
| T | Must be std::size_t and a different type from uint64_t. |
std::size_t. size_t and uint64_t are the same type; static_cast<std::size_t> then uses operator uint64_t. A count above size_t is undefined. Checked with assert when assertions are on. Adds other to this size.
| other | Addend. |
uint64_t is undefined. Checked with assert when assertions are on. Subtracts other from this size.
| other | Subtrahend. |
*this < other is undefined. Checked with assert when assertions are on.
|
inlineconstexprnoexcept |
Assign an integer count.
| T | Integral type. |
| value | Byte count. |
value is undefined. Checked with assert when assertions are on.
|
inlineconstexprnoexcept |
Stored count.
uint64_t. Sum.
| lhs | Left addend. |
| rhs | Right addend. |
uint64_t is undefined. Checked with assert when assertions are on. Difference.
| lhs | Minuend. |
| rhs | Subtrahend. |
lhs < rhs is undefined. Checked with assert when assertions are on. Numeric order.
| lhs | Left count. |
| rhs | Right count. |
Numeric equality.
| lhs | Left count. |
| rhs | Right count. |