xo-unit: + (Quantity * Dimensionless) and vice versa

This commit is contained in:
Roland Conybeare 2024-04-24 11:32:37 -04:00
commit b32363b848

View file

@ -214,6 +214,24 @@ namespace xo {
return Quantity::multiply(x, y);
}
/** note: does not require unit scaling, so constexpr with c++23 **/
template <typename Dimensionless, typename Quantity>
requires std::is_arithmetic_v<Dimensionless> && quantity2_concept<Quantity>
constexpr auto
operator* (Dimensionless x, const Quantity & y)
{
return y.scale_by(x);
}
/** note: does not require unit scaling, so constexpr with c++23 **/
template <typename Dimensionless, typename Quantity>
requires std::is_arithmetic_v<Dimensionless> && quantity2_concept<Quantity>
constexpr auto
operator* (const Quantity & x, Dimensionless y)
{
return x.scale_by(y);
}
/** note: won't have constexpr result until c++26 (when ::sqrt(), ::pow() are constexpr)
**/
template <typename Quantity, typename Quantity2>