From 2b3c9a6afae5e01f099f9a479e4603c540fa7d9b Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Wed, 13 Sep 2023 20:06:17 +0200 Subject: [PATCH] feat: `quantity_point` compound assignment now preserves the value category --- src/core/include/mp-units/quantity_point.h | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/core/include/mp-units/quantity_point.h b/src/core/include/mp-units/quantity_point.h index 1f4a4940a..68dc3c4f9 100644 --- a/src/core/include/mp-units/quantity_point.h +++ b/src/core/include/mp-units/quantity_point.h @@ -224,18 +224,22 @@ class quantity_point { } // compound assignment operators - constexpr quantity_point& operator+=(const quantity_type& q) - requires requires { quantity_from_origin_ += q; } + template + requires std::derived_from, quantity_point> && + requires(quantity_type q) { quantity_from_origin_ += q; } + friend constexpr decltype(auto) operator+=(QP&& qp, const quantity_type& q) { - quantity_from_origin_ += q; - return *this; + qp.quantity_from_origin_ += q; + return std::forward(qp); } - constexpr quantity_point& operator-=(const quantity_type& q) - requires requires { quantity_from_origin_ -= q; } + template + requires std::derived_from, quantity_point> && + requires(quantity_type q) { quantity_from_origin_ -= q; } + friend constexpr decltype(auto) operator-=(QP&& qp, const quantity_type& q) { - quantity_from_origin_ -= q; - return *this; + qp.quantity_from_origin_ -= q; + return std::forward(qp); } private: