From b32363b848d47872732fcfc3a5ecd52e6f476c0e Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Wed, 24 Apr 2024 11:32:37 -0400 Subject: [PATCH] xo-unit: + (Quantity * Dimensionless) and vice versa --- include/xo/unit/Quantity.hpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/include/xo/unit/Quantity.hpp b/include/xo/unit/Quantity.hpp index aaf29d73..d24f2589 100644 --- a/include/xo/unit/Quantity.hpp +++ b/include/xo/unit/Quantity.hpp @@ -214,6 +214,24 @@ namespace xo { return Quantity::multiply(x, y); } + /** note: does not require unit scaling, so constexpr with c++23 **/ + template + requires std::is_arithmetic_v && quantity2_concept + 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 + requires std::is_arithmetic_v && quantity2_concept + 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