Quantity

template<IsDimensionality Dim, IsRatioOrTag Scale>
class Quantity

Primary template for representing physical quantities with dimensions and scale.

This class template provides type-safe representation of physical quantities with automatic unit conversion, dimensional analysis, and arithmetic operations. It stores values internally and provides conversion to SI units through the scale parameter.

Template Parameters:
  • Dim – The dimensionality of the quantity (e.g., Length, Time, Mass)

  • Scale – The scale/ratio for unit conversion (e.g., std::kilo, std::milli) or a unit tag

Public Types

using dimension_type = Dim
using scale_type = Scale

Public Functions

template<IsNumeric T>
inline explicit constexpr Quantity(T value)
template<IsRatioOrTag OtherScale>
inline constexpr Quantity(const Quantity<Dim, OtherScale> &other)
inline constexpr Quantity()
inline constexpr Quantity(const Quantity &other)
inline Quantity &operator=(const Quantity &other)
inline constexpr operator double() const
double to_si() const

Get the value in SI units.

Converts the internal value to the SI base unit for this dimension by applying the appropriate scale conversion.

Template Parameters:
  • Dim – The dimensionality of the quantity

  • Scale – The scale type of the quantity

Returns:

double The value converted to SI units

double value() const

Get the raw value in the current scale.

Returns the stored value without any unit conversion.

Template Parameters:
  • Dim – The dimensionality of the quantity

  • Scale – The scale type of the quantity

Returns:

double The value in the current unit scale

double raw_value() const

Get the raw value (alias for value())

Returns the stored value without any unit conversion. This is an alias for value() provided for compatibility.

Template Parameters:
  • Dim – The dimensionality of the quantity

  • Scale – The scale type of the quantity

Returns:

double The value in the current unit scale

template<IsRatioOrTag NewScale>
inline Quantity<Dim, NewScale> as() const
template<typename QuantityType>
inline auto as() const
std::string to_string() const

Convert quantity to string representation.

Formats the quantity as a string with the SI value followed by the SI unit string for this dimension.

Template Parameters:
  • Dim – The dimensionality of the quantity

  • Scale – The scale type of the quantity

Returns:

std::string String representation showing value and SI unit

inline Quantity operator+(const Quantity &other) const
inline Quantity operator-(const Quantity &other) const
inline Quantity &operator+=(const Quantity &other)
inline Quantity &operator-=(const Quantity &other)
inline Quantity operator*(double scalar) const
inline Quantity operator/(double scalar) const
inline Quantity &operator*=(double scalar)
inline Quantity &operator/=(double scalar)
inline bool operator==(const Quantity &other) const
inline bool operator!=(const Quantity &other) const
inline bool operator<(const Quantity &other) const
inline bool operator>(const Quantity &other) const
inline bool operator<=(const Quantity &other) const
inline bool operator>=(const Quantity &other) const
inline Quantity operator-() const
double to_si(double value) const
double to_si(double value) const

Friends

inline friend std::ostream &operator<<(std::ostream &os, const Quantity &quantity)