From 633c037ba382f6bfc3d4f3cdd9ca2f9b5794db16 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Fri, 3 May 2024 21:34:55 -0400 Subject: [PATCH] xo-unit: + with_repr() convenience for xo::qty::quantity --- include/xo/unit/quantity.hpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/include/xo/unit/quantity.hpp b/include/xo/unit/quantity.hpp index 5b3a810c..8947c9c0 100644 --- a/include/xo/unit/quantity.hpp +++ b/include/xo/unit/quantity.hpp @@ -44,6 +44,12 @@ namespace xo { // zero_qty // reciprocal + template + constexpr + auto with_repr() const { + return quantity(scale_); + } + /* parallel implementation to Quantity::rescale(), * except that NaturalUnit2 is a compile-time-only template-argument * @@ -142,7 +148,7 @@ namespace xo { requires(quantity_concept && Q2::always_constexpr_unit) constexpr operator Q2() const { - return this->template rescale(); + return this->template rescale().template with_repr(); } public: /* need public members so that a quantity instance can be a non-type template parameter (is a structural type) */ @@ -236,6 +242,15 @@ namespace xo { return x.template rescale(); } + template + requires (quantity_concept + && Q1::always_constexpr_unit) + constexpr auto + with_repr(const Q1 & x) + { + return x.template with_repr(); + } + /** note: won't have constexpr result w/ fractional dimension until c++26 (when ::sqrt(), ::pow() are constexpr) **/ template