feat: quantity_point compound assignment now preserves the value category

This commit is contained in:
Mateusz Pusz
2023-09-13 20:06:17 +02:00
parent 2e26eed59d
commit 2b3c9a6afa

View File

@@ -224,18 +224,22 @@ public:
} }
// compound assignment operators // compound assignment operators
constexpr quantity_point& operator+=(const quantity_type& q) template<typename QP>
requires requires { quantity_from_origin_ += q; } requires std::derived_from<std::remove_cvref_t<QP>, 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; qp.quantity_from_origin_ += q;
return *this; return std::forward<QP>(qp);
} }
constexpr quantity_point& operator-=(const quantity_type& q) template<typename QP>
requires requires { quantity_from_origin_ -= q; } requires std::derived_from<std::remove_cvref_t<QP>, 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; qp.quantity_from_origin_ -= q;
return *this; return std::forward<QP>(qp);
} }
private: private: