diff --git a/docs/install.rst b/docs/install.rst index 049efc8b..ded68291 100644 --- a/docs/install.rst +++ b/docs/install.rst @@ -65,11 +65,7 @@ Installing from source ---------------------- Install scripts for `xo-unit`, `xo-ratio` and `xo-flatstring` depend on shared cmake macros -and a bootstrap script `xo-cmake-config`. - -* `xo-cmake`_ source - -.. _xo-cmake: https://github.com/rconybea/xo-cmake +and a bootstrap script `xo-cmake-config` fro `xo-cmake`. Preamble: diff --git a/include/xo/unit/quantity.hpp b/include/xo/unit/quantity.hpp index 2691e239..e145db16 100644 --- a/include/xo/unit/quantity.hpp +++ b/include/xo/unit/quantity.hpp @@ -264,8 +264,23 @@ namespace xo { return *this; } - // operator*= - // operator/= + /** multiply @p y in-place. y must be dimensionless **/ + template + requires std::is_arithmetic_v + constexpr + quantity & operator*=(Dimensionless y) { + this->scale_ *= y; + return *this; + } + + /** divide @p y in-place. y must be dimensionless **/ + template + requires std::is_arithmetic_v + constexpr + quantity & operator/=(Dimensionless y) { + this->scale_ /= y; + return *this; + } ///@} @@ -634,6 +649,40 @@ namespace xo { return detail::quantity_util::subtract(x, y); } + /** subtract an arithmetic value from a dimensionless quantity **/ + template + requires (quantity_concept + && Quantity::is_dimensionless() + && std::is_arithmetic_v) + constexpr auto + operator- (const Quantity & x, Dimensionless y) + { + using repr_type = std::common_type_t; + + auto xp = static_cast(x.scale()); + auto yp = static_cast(y); + + return xp - yp; + } + + /** subtract a dimensionless quantity from an arithmetic value **/ + template + requires (std::is_arithmetic_v + && quantity_concept + && Quantity::is_dimensionless()) + constexpr auto + operator- (Dimensionless x, const Quantity & y) + { + using repr_type = std::common_type_t; + + auto xp = static_cast(x); + auto yp = static_cast(y.scale()); + + return xp - yp; + } + ///@} namespace qty { diff --git a/include/xo/unit/quantity_ops.hpp b/include/xo/unit/quantity_ops.hpp index 8f134028..28465be9 100644 --- a/include/xo/unit/quantity_ops.hpp +++ b/include/xo/unit/quantity_ops.hpp @@ -9,45 +9,6 @@ namespace xo { namespace qty { - /** @defgroup quantity-dimensionless-operators **/ - ///@{ - - /** subtract an arithmetic value from a dimensionless quantity **/ - template - requires (quantity_concept - && Quantity::is_dimensionless() - && std::is_arithmetic_v) - constexpr auto - operator- (const Quantity & x, Dimensionless y) - { - using repr_type = std::common_type_t; - - auto xp = static_cast(x.scale()); - auto yp = static_cast(y); - - return xp - yp; - } - - /** subtract a dimensionless quantity from an arithmetic value **/ - template - requires (std::is_arithmetic_v - && quantity_concept - && Quantity::is_dimensionless()) - constexpr auto - operator- (Dimensionless x, const Quantity & y) - { - using repr_type = std::common_type_t; - - auto xp = static_cast(x); - auto yp = static_cast(y.scale()); - - return xp - yp; - } - - ///@} - /** note: won't have constexpr result until c++26 (when ::sqrt(), ::pow() are constexpr) **/ template