mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-04 12:54:25 +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_);
|
return make_quantity<reference>(-numerical_value_);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr quantity& operator++()
|
template<typename Q>
|
||||||
requires requires(rep v) {
|
friend constexpr decltype(auto) operator++(Q&& q)
|
||||||
|
requires std::derived_from<std::remove_cvref_t<Q>, quantity> && requires(rep v) {
|
||||||
{
|
{
|
||||||
++v
|
++v
|
||||||
} -> std::same_as<rep&>;
|
} -> std::same_as<rep&>;
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
++numerical_value_;
|
++q.numerical_value_;
|
||||||
return *this;
|
return std::forward<Q>(q);
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] constexpr Quantity auto operator++(int)
|
[[nodiscard]] constexpr Quantity auto operator++(int)
|
||||||
@@ -231,15 +232,16 @@ public:
|
|||||||
return make_quantity<reference>(numerical_value_++);
|
return make_quantity<reference>(numerical_value_++);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr quantity& operator--()
|
template<typename Q>
|
||||||
requires requires(rep v) {
|
friend constexpr decltype(auto) operator--(Q&& q)
|
||||||
|
requires std::derived_from<std::remove_cvref_t<Q>, quantity> && requires(rep v) {
|
||||||
{
|
{
|
||||||
--v
|
--v
|
||||||
} -> std::same_as<rep&>;
|
} -> std::same_as<rep&>;
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
--numerical_value_;
|
--q.numerical_value_;
|
||||||
return *this;
|
return std::forward<Q>(q);
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] constexpr Quantity auto operator--(int)
|
[[nodiscard]] constexpr Quantity auto operator--(int)
|
||||||
|
@@ -183,11 +183,12 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// member unary operators
|
// member unary operators
|
||||||
constexpr quantity_point& operator++()
|
template<typename QP>
|
||||||
requires requires { ++quantity_from_origin_; }
|
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_;
|
++qp.quantity_from_origin_;
|
||||||
return *this;
|
return std::forward<QP>(qp);
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] constexpr quantity_point operator++(int)
|
[[nodiscard]] constexpr quantity_point operator++(int)
|
||||||
@@ -196,11 +197,12 @@ public:
|
|||||||
return quantity_point(quantity_from_origin_++);
|
return quantity_point(quantity_from_origin_++);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr quantity_point& operator--()
|
template<typename QP>
|
||||||
requires requires { --quantity_from_origin_; }
|
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_;
|
--qp.quantity_from_origin_;
|
||||||
return *this;
|
return std::forward<QP>(qp);
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] constexpr quantity_point operator--(int)
|
[[nodiscard]] constexpr quantity_point operator--(int)
|
||||||
|
Reference in New Issue
Block a user