StormByte 2.0.0
C++26 foundation of the StormByte suite
 
Loading...
Searching...
No Matches
StormByte::Size Class Referencefinal

Count of abstract units (uint64_t storage). More...

#include <StormByte/size.hxx>

Public Member Functions

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.
 
constexpr operator std::size_t () const noexcept
 Implicit host size_t (clamped).
 
template<Type::Integral T>
requires (!Type::SameAs<T, std::size_t>)
constexpr operator T () const noexcept
 Explicit conversion to an integral other than std::size_t.
 
 operator CString () const noexcept
 Decimal text owned by Base.
 
 operator WCString () const noexcept
 Decimal wide text owned by Base.
 
STORMBYTE_FORCE_INLINE operator std::string () const
 Decimal text on the caller heap.
 
constexpr Size & operator++ () noexcept
 Prefix increment.
 
constexpr Size operator++ (int) noexcept
 Postfix increment.
 
constexpr Size & operator-- () noexcept
 Prefix decrement.
 
constexpr Size operator-- (int) noexcept
 Postfix decrement.
 
constexpr Size & operator+= (Size other) noexcept
 Add other.
 
constexpr Size & operator-= (Size other) noexcept
 Subtract other.
 
constexpr Size & operator*= (Size other) noexcept
 Multiply by other.
 
constexpr Size & operator/= (Size other) noexcept
 Divide by other.
 
constexpr Size & operator%= (Size other) noexcept
 Remainder with other.
 
template<Type::Integral T>
constexpr Size & operator+= (T value) noexcept
 Add an integer.
 
template<Type::Integral T>
constexpr Size & operator-= (T value) noexcept
 Subtract an integer.
 
template<Type::Integral T>
constexpr Size & operator*= (T value) noexcept
 Multiply by an integer.
 
template<Type::Integral T>
constexpr Size & operator/= (T value) noexcept
 Divide by an integer.
 
template<Type::Integral T>
constexpr Size & operator%= (T value) noexcept
 Remainder with an integer.
 

Friends

constexpr bool operator== (Size lhs, Size rhs) noexcept
 Numeric equality.
 
template<Type::Integral T>
constexpr bool operator== (Size lhs, T rhs) noexcept
 Mixed equality.
 
template<Type::Integral T>
constexpr bool operator== (T lhs, Size rhs) noexcept
 Mixed equality.
 
constexpr std::strong_ordering operator<=> (Size lhs, Size rhs) noexcept
 Numeric order.
 
template<Type::Integral T>
constexpr std::strong_ordering operator<=> (Size lhs, T rhs) noexcept
 Mixed order.
 
template<Type::Integral T>
constexpr std::strong_ordering operator<=> (T lhs, Size rhs) noexcept
 Mixed order.
 
constexpr Size operator+ (Size lhs, Size rhs) noexcept
 Sum.
 
constexpr Size operator- (Size lhs, Size rhs) noexcept
 Difference.
 
constexpr Size operator* (Size lhs, Size rhs) noexcept
 Product.
 
constexpr Size operator/ (Size lhs, Size rhs) noexcept
 Quotient.
 
constexpr Size operator% (Size lhs, Size rhs) noexcept
 Remainder.
 
template<Type::Integral T>
constexpr Size operator+ (Size lhs, T rhs) noexcept
 Mixed sum.
 
template<Type::Integral T>
constexpr Size operator+ (T lhs, Size rhs) noexcept
 Mixed sum.
 
template<Type::Integral T>
constexpr Size operator- (Size lhs, T rhs) noexcept
 Mixed difference.
 
template<Type::Integral T>
constexpr Size operator- (T lhs, Size rhs) noexcept
 Mixed difference.
 
template<Type::Integral T>
constexpr Size operator* (Size lhs, T rhs) noexcept
 Mixed product.
 
template<Type::Integral T>
constexpr Size operator* (T lhs, Size rhs) noexcept
 Mixed product.
 
template<Type::Integral T>
constexpr Size operator/ (Size lhs, T rhs) noexcept
 Mixed quotient.
 
template<Type::Integral T>
constexpr Size operator/ (T lhs, Size rhs) noexcept
 Mixed quotient.
 
template<Type::Integral T>
constexpr Size operator% (Size lhs, T rhs) noexcept
 Mixed remainder.
 
template<Type::Integral T>
constexpr Size operator% (T lhs, Size rhs) noexcept
 Mixed remainder.
 

Detailed Description

Count of abstract units (uint64_t storage).

Not a byte length. Not std::size_t. Not std::ptrdiff_t. The value that crosses a DLL is always 64-bit unsigned.

Arithmetic always yields Size. Integer operands are absorbed. std::size_t calc = size1 + 3 * size2 does the math in uint64_t and converts once at the end.

Overflow of uint64_t and a negative result: assert when assertions are on; wrap modulo 2⁶⁴ when they are not. Division by zero: assert when assertions are on; undefined otherwise.

Implicit conversion exists only to std::size_t (clamp to size_t::max). Every other integral destination is explicit and clamps to T::max. There is no operator bool and no Value().

On hosts where std::size_t is unsigned long or unsigned long long, that conversion is the implicit operator std::size_t. Those two names are not given a second extern template of operator T().

Mixed comparison with any Type::Integral is a hidden friend so s == 5, 5u == s and ASSERT_EQUAL are not ambiguous with the built-in candidates. Comparison with StormByte::ByteSize lives in byte_size.hxx.

operator CString / operator WCString print decimal digits.

Constructor & Destructor Documentation

◆ Size() [1/4]

constexpr StormByte::Size::Size ( )
inlineconstexprnoexcept

Zero.

◆ Size() [2/4]

template<Type::Integral T>
constexpr StormByte::Size::Size ( T  value)
inlineconstexprnoexcept

From an integer count.

Template Parameters
TIntegral type.
Parameters
valueCount. Negative is undefined (assert when on).

◆ Size() [3/4]

constexpr StormByte::Size::Size ( const Size &  other)
constexprdefaultnoexcept

Copy constructor.

Parameters
otherCount to copy.

◆ Size() [4/4]

constexpr StormByte::Size::Size ( Size &&  other)
constexprdefaultnoexcept

Move constructor.

Parameters
otherCount to take.

◆ ~Size()

constexpr StormByte::Size::~Size ( )
constexprdefaultnoexcept

Destructor.

Member Function Documentation

◆ operator CString()

StormByte::Size::operator CString ( ) const
explicitnoexcept

Decimal text owned by Base.

Returns
Digits, no unit suffix.

◆ operator std::size_t()

constexpr StormByte::Size::operator std::size_t ( ) const
inlineconstexprnoexcept

Implicit host size_t (clamped).

Returns
Count as std::size_t.

◆ operator std::string()

STORMBYTE_FORCE_INLINE StormByte::Size::operator std::string ( ) const
inline

Decimal text on the caller heap.

Returns
Digits, no unit suffix.

◆ operator T()

template<Type::Integral T>
requires (!Type::SameAs<T, std::size_t>)
constexpr StormByte::Size::operator T ( ) const
inlineexplicitconstexprnoexcept

Explicit conversion to an integral other than std::size_t.

Template Parameters
TIntegral type, not std::size_t.
Returns
Count clamped to std::numeric_limits<T>::max().

◆ operator WCString()

StormByte::Size::operator WCString ( ) const
explicitnoexcept

Decimal wide text owned by Base.

Returns
Digits, no unit suffix.

◆ operator%=() [1/2]

constexpr Size & StormByte::Size::operator%= ( Size  other)
inlineconstexprnoexcept

Remainder with other.

Parameters
otherDivisor.
Returns
*this.

◆ operator%=() [2/2]

template<Type::Integral T>
constexpr Size & StormByte::Size::operator%= ( T  value)
inlineconstexprnoexcept

Remainder with an integer.

Template Parameters
TIntegral type.
Parameters
valueDivisor.
Returns
*this.

◆ operator*=() [1/2]

constexpr Size & StormByte::Size::operator*= ( Size  other)
inlineconstexprnoexcept

Multiply by other.

Parameters
otherFactor.
Returns
*this.

◆ operator*=() [2/2]

template<Type::Integral T>
constexpr Size & StormByte::Size::operator*= ( T  value)
inlineconstexprnoexcept

Multiply by an integer.

Template Parameters
TIntegral type.
Parameters
valueFactor.
Returns
*this.

◆ operator++() [1/2]

constexpr Size & StormByte::Size::operator++ ( )
inlineconstexprnoexcept

Prefix increment.

Returns
*this after adding one.

◆ operator++() [2/2]

constexpr Size StormByte::Size::operator++ ( int  )
inlineconstexprnoexcept

Postfix increment.

Returns
Copy before adding one.

◆ operator+=() [1/2]

constexpr Size & StormByte::Size::operator+= ( Size  other)
inlineconstexprnoexcept

Add other.

Parameters
otherAddend.
Returns
*this.

◆ operator+=() [2/2]

template<Type::Integral T>
constexpr Size & StormByte::Size::operator+= ( T  value)
inlineconstexprnoexcept

Add an integer.

Template Parameters
TIntegral type.
Parameters
valueAddend.
Returns
*this.

◆ operator--() [1/2]

constexpr Size & StormByte::Size::operator-- ( )
inlineconstexprnoexcept

Prefix decrement.

Returns
*this after subtracting one.

◆ operator--() [2/2]

constexpr Size StormByte::Size::operator-- ( int  )
inlineconstexprnoexcept

Postfix decrement.

Returns
Copy before subtracting one.

◆ operator-=() [1/2]

constexpr Size & StormByte::Size::operator-= ( Size  other)
inlineconstexprnoexcept

Subtract other.

Parameters
otherSubtrahend.
Returns
*this.

◆ operator-=() [2/2]

template<Type::Integral T>
constexpr Size & StormByte::Size::operator-= ( T  value)
inlineconstexprnoexcept

Subtract an integer.

Template Parameters
TIntegral type.
Parameters
valueSubtrahend.
Returns
*this.

◆ operator/=() [1/2]

constexpr Size & StormByte::Size::operator/= ( Size  other)
inlineconstexprnoexcept

Divide by other.

Parameters
otherDivisor.
Returns
*this.

◆ operator/=() [2/2]

template<Type::Integral T>
constexpr Size & StormByte::Size::operator/= ( T  value)
inlineconstexprnoexcept

Divide by an integer.

Template Parameters
TIntegral type.
Parameters
valueDivisor.
Returns
*this.

◆ operator=() [1/3]

constexpr Size & StormByte::Size::operator= ( const Size &  other)
constexprdefaultnoexcept

Copy assignment.

Parameters
otherCount to copy.
Returns
*this.

◆ operator=() [2/3]

constexpr Size & StormByte::Size::operator= ( Size &&  other)
constexprdefaultnoexcept

Move assignment.

Parameters
otherCount to take.
Returns
*this.

◆ operator=() [3/3]

template<Type::Integral T>
constexpr Size & StormByte::Size::operator= ( T  value)
inlineconstexprnoexcept

Assign an integer count.

Template Parameters
TIntegral type.
Parameters
valueCount. Negative is undefined (assert when on).
Returns
*this.

Friends And Related Symbol Documentation

◆ operator% [1/3]

constexpr Size operator% ( Size  lhs,
Size  rhs 
)
friend

Remainder.

Parameters
lhsDividend.
rhsDivisor.
Returns
Remainder as Size.

◆ operator% [2/3]

template<Type::Integral T>
constexpr Size operator% ( Size  lhs,
T  rhs 
)
friend

Mixed remainder.

Template Parameters
TIntegral type.
TIntegral type.
Parameters
lhsDividend.
rhsDivisor.
Returns
Remainder as Size.

◆ operator% [3/3]

template<Type::Integral T>
constexpr Size operator% ( T  lhs,
Size  rhs 
)
friend

Mixed remainder.

Template Parameters
TIntegral type.
TIntegral type.
Parameters
lhsDividend.
rhsDivisor.
Returns
Remainder as Size.

◆ operator* [1/3]

constexpr Size operator* ( Size  lhs,
Size  rhs 
)
friend

Product.

Parameters
lhsLeft factor.
rhsRight factor.
Returns
Product as Size.

◆ operator* [2/3]

template<Type::Integral T>
constexpr Size operator* ( Size  lhs,
T  rhs 
)
friend

Mixed product.

Template Parameters
TIntegral type.
TIntegral type.
Parameters
lhsLeft factor.
rhsRight factor.
Returns
Product as Size.

◆ operator* [3/3]

template<Type::Integral T>
constexpr Size operator* ( T  lhs,
Size  rhs 
)
friend

Mixed product.

Template Parameters
TIntegral type.
TIntegral type.
Parameters
lhsLeft factor.
rhsRight factor.
Returns
Product as Size.

◆ operator+ [1/3]

constexpr Size operator+ ( Size  lhs,
Size  rhs 
)
friend

Sum.

Parameters
lhsLeft addend.
rhsRight addend.
Returns
Sum as Size.

◆ operator+ [2/3]

template<Type::Integral T>
constexpr Size operator+ ( Size  lhs,
T  rhs 
)
friend

Mixed sum.

Template Parameters
TIntegral type.
TIntegral type.
Parameters
lhsLeft addend.
rhsRight addend.
Returns
Sum as Size.

◆ operator+ [3/3]

template<Type::Integral T>
constexpr Size operator+ ( T  lhs,
Size  rhs 
)
friend

Mixed sum.

Template Parameters
TIntegral type.
TIntegral type.
Parameters
lhsLeft addend.
rhsRight addend.
Returns
Sum as Size.

◆ operator- [1/3]

constexpr Size operator- ( Size  lhs,
Size  rhs 
)
friend

Difference.

Parameters
lhsMinuend.
rhsSubtrahend.
Returns
Difference as Size.

◆ operator- [2/3]

template<Type::Integral T>
constexpr Size operator- ( Size  lhs,
T  rhs 
)
friend

Mixed difference.

Template Parameters
TIntegral type.
TIntegral type.
Parameters
lhsMinuend.
rhsSubtrahend.
Returns
Difference as Size.

◆ operator- [3/3]

template<Type::Integral T>
constexpr Size operator- ( T  lhs,
Size  rhs 
)
friend

Mixed difference.

Template Parameters
TIntegral type.
TIntegral type.
Parameters
lhsMinuend.
rhsSubtrahend.
Returns
Difference as Size.

◆ operator/ [1/3]

constexpr Size operator/ ( Size  lhs,
Size  rhs 
)
friend

Quotient.

Parameters
lhsDividend.
rhsDivisor.
Returns
Quotient as Size.

◆ operator/ [2/3]

template<Type::Integral T>
constexpr Size operator/ ( Size  lhs,
T  rhs 
)
friend

Mixed quotient.

Template Parameters
TIntegral type.
TIntegral type.
Parameters
lhsDividend.
rhsDivisor.
Returns
Quotient as Size.

◆ operator/ [3/3]

template<Type::Integral T>
constexpr Size operator/ ( T  lhs,
Size  rhs 
)
friend

Mixed quotient.

Template Parameters
TIntegral type.
TIntegral type.
Parameters
lhsDividend.
rhsDivisor.
Returns
Quotient as Size.

◆ operator<=> [1/3]

constexpr std::strong_ordering operator<=> ( Size  lhs,
Size  rhs 
)
friend

Numeric order.

Parameters
lhsLeft count.
rhsRight count.
Returns
Ordering.

◆ operator<=> [2/3]

template<Type::Integral T>
constexpr std::strong_ordering operator<=> ( Size  lhs,
T  rhs 
)
friend

Mixed order.

Template Parameters
TIntegral type.
TIntegral type.
Parameters
lhsLeft count.
rhsRight integer.
Returns
Ordering.

◆ operator<=> [3/3]

template<Type::Integral T>
constexpr std::strong_ordering operator<=> ( T  lhs,
Size  rhs 
)
friend

Mixed order.

Template Parameters
TIntegral type.
TIntegral type.
Parameters
lhsLeft integer.
rhsRight count.
Returns
Ordering.

◆ operator== [1/3]

constexpr bool operator== ( Size  lhs,
Size  rhs 
)
friend

Numeric equality.

Parameters
lhsLeft count.
rhsRight count.
Returns
Whether the counts are equal.

◆ operator== [2/3]

template<Type::Integral T>
constexpr bool operator== ( Size  lhs,
T  rhs 
)
friend

Mixed equality.

Template Parameters
TIntegral type.
TIntegral type.
Parameters
lhsLeft count.
rhsRight integer.
Returns
Whether the numeric values match.

◆ operator== [3/3]

template<Type::Integral T>
constexpr bool operator== ( T  lhs,
Size  rhs 
)
friend

Mixed equality.

Template Parameters
TIntegral type.
TIntegral type.
Parameters
lhsLeft integer.
rhsRight count.
Returns
Whether the numeric values match.

The documentation for this class was generated from the following file: