Skip to content

Commit

Permalink
feat: quantity_point compound assignment now preserves the value ca…
Browse files Browse the repository at this point in the history
…tegory
  • Loading branch information
mpusz committed Sep 13, 2023
1 parent 2e26eed commit 2b3c9a6
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/core/include/mp-units/quantity_point.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<typename QP>
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;
return *this;
qp.quantity_from_origin_ += q;
return std::forward<QP>(qp);
}

constexpr quantity_point& operator-=(const quantity_type& q)
requires requires { quantity_from_origin_ -= q; }
template<typename QP>
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;
return *this;
qp.quantity_from_origin_ -= q;
return std::forward<QP>(qp);
}

private:
Expand Down

0 comments on commit 2b3c9a6

Please sign in to comment.