5 Quantities and units library [quantities]

5.6 Quantity [qty]

5.6.10 Compound assignment operations [qty.assign.ops]

In the following descriptions, let @ be the operator.
template<Mutable<quantity> Q, auto R2, typename Rep2> requires see below friend constexpr decltype(auto) operator+=(Q&& lhs, const quantity<R2, Rep2>& rhs); template<Mutable<quantity> Q, auto R2, typename Rep2> requires see below friend constexpr decltype(auto) operator-=(Q&& lhs, const quantity<R2, Rep2>& rhs); template<Mutable<quantity> Q, auto R2, typename Rep2> requires see below friend constexpr decltype(auto) operator%=(Q&& lhs, const quantity<R2, Rep2>& rhs);
Preconditions: If @ is %=, then is_neq_zero(rhs) is true.
Effects: Equivalent to lhs.numerical-value @ rhs.in(lhs.unit).numerical-value.
Returns: std​::​forward<Q>(lhs).
Remarks: Let C be
  • (!treat_as_floating_point<rep>) if @ is %=, and
  • true otherwise.
The expression in the requires-clause is equivalent to: QuantityConvertibleTo<quantity<R2, Rep2>, quantity> && C && requires(rep& a, const Rep2 b) { { a @ b } -> std::same_as<rep&>; }
Recommended practice: If equivalent(unit, get_unit(rhs.reference)) is true, then the expression rhs.in(lhs.unit) is replaced with rhs.
template<Mutable<quantity> Q, ValuePreservingTo<Rep> Value> requires see below friend constexpr decltype(auto) operator*=(Q&& lhs, const Value& rhs); template<Mutable<quantity> Q, ValuePreservingTo<Rep> Value> requires see below friend constexpr decltype(auto) operator/=(Q&& lhs, const Value& rhs);
Preconditions: If @ is /=, then rhs != representation_values<Value>​::​zero() is true.
Effects: Equivalent to lhs.numerical-value @ rhs.
Returns: std​::​forward<Q>(lhs).
Remarks: The expression in the requires-clause is equivalent to: (!Quantity<Value>) && requires(rep& a, const Value b) { { a @ b } -> std::same_as<rep&>; }
template<Mutable<quantity> Q, QuantityOf<dimensionless> Q2> requires see below friend constexpr decltype(auto) operator*=(Q&& lhs, const Q2& rhs); template<Mutable<quantity> Q, QuantityOf<dimensionless> Q2> requires see below friend constexpr decltype(auto) operator/=(Q&& lhs, const Q2& rhs);
Effects: Equivalent to: return std​::​forward<Q>(lhs) @ rhs.numerical-value;
Remarks: The expression in the requires-clause is equivalent to: (Q2::unit == ::mp_units::one) && ValuePreservingTo<typename Q2::rep, Rep> && requires(rep& a, const Q2::rep b) { { a @ b } -> std::same_as<rep&>; }