mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-04 04:44:27 +02:00
feat: pre-increment and pre-decrement operators now preserve value category
This commit is contained in:
@@ -210,15 +210,16 @@ public:
|
||||
return make_quantity<reference>(-numerical_value_);
|
||||
}
|
||||
|
||||
constexpr quantity& operator++()
|
||||
requires requires(rep v) {
|
||||
template<typename Q>
|
||||
friend constexpr decltype(auto) operator++(Q&& q)
|
||||
requires std::derived_from<std::remove_cvref_t<Q>, quantity> && requires(rep v) {
|
||||
{
|
||||
++v
|
||||
} -> std::same_as<rep&>;
|
||||
}
|
||||
{
|
||||
++numerical_value_;
|
||||
return *this;
|
||||
++q.numerical_value_;
|
||||
return std::forward<Q>(q);
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr Quantity auto operator++(int)
|
||||
@@ -231,15 +232,16 @@ public:
|
||||
return make_quantity<reference>(numerical_value_++);
|
||||
}
|
||||
|
||||
constexpr quantity& operator--()
|
||||
requires requires(rep v) {
|
||||
template<typename Q>
|
||||
friend constexpr decltype(auto) operator--(Q&& q)
|
||||
requires std::derived_from<std::remove_cvref_t<Q>, quantity> && requires(rep v) {
|
||||
{
|
||||
--v
|
||||
} -> std::same_as<rep&>;
|
||||
}
|
||||
{
|
||||
--numerical_value_;
|
||||
return *this;
|
||||
--q.numerical_value_;
|
||||
return std::forward<Q>(q);
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr Quantity auto operator--(int)
|
||||
|
@@ -183,11 +183,12 @@ public:
|
||||
}
|
||||
|
||||
// member unary operators
|
||||
constexpr quantity_point& operator++()
|
||||
requires requires { ++quantity_from_origin_; }
|
||||
template<typename QP>
|
||||
friend constexpr decltype(auto) operator++(QP&& qp)
|
||||
requires std::derived_from<std::remove_cvref_t<QP>, quantity_point> && requires { ++qp.quantity_from_origin_; }
|
||||
{
|
||||
++quantity_from_origin_;
|
||||
return *this;
|
||||
++qp.quantity_from_origin_;
|
||||
return std::forward<QP>(qp);
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr quantity_point operator++(int)
|
||||
@@ -196,11 +197,12 @@ public:
|
||||
return quantity_point(quantity_from_origin_++);
|
||||
}
|
||||
|
||||
constexpr quantity_point& operator--()
|
||||
requires requires { --quantity_from_origin_; }
|
||||
template<typename QP>
|
||||
friend constexpr decltype(auto) operator--(QP&& qp)
|
||||
requires std::derived_from<std::remove_cvref_t<QP>, quantity_point> && requires { --qp.quantity_from_origin_; }
|
||||
{
|
||||
--quantity_from_origin_;
|
||||
return *this;
|
||||
--qp.quantity_from_origin_;
|
||||
return std::forward<QP>(qp);
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr quantity_point operator--(int)
|
||||
|
Reference in New Issue
Block a user