From be56b6f6092299d6282d849f550712e571671c20 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Wed, 24 Apr 2024 11:32:17 -0400 Subject: [PATCH] xo-unit: + Quantity.compare() --- include/xo/unit/Quantity.hpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/include/xo/unit/Quantity.hpp b/include/xo/unit/Quantity.hpp index 3dd82eaf..aaf29d73 100644 --- a/include/xo/unit/Quantity.hpp +++ b/include/xo/unit/Quantity.hpp @@ -94,7 +94,7 @@ namespace xo { * static_cast(y.scale())); return Quantity(r_scale, - rr.natural_unit_); + rr.natural_unit_); } template @@ -169,6 +169,14 @@ namespace xo { } } + template + static constexpr + auto compare(const Quantity & x, const Quantity2 & y) { + Quantity y2 = y.rescale(x.unit_); + + return x.scale() <=> y2.scale(); + } + private: /** @brief quantity represents this multiple of a unit amount **/ Repr scale_ = Repr{};