Skip to content

Commit

Permalink
refactor: Forwarding renamed to Mutable
Browse files Browse the repository at this point in the history
Resolves #215
  • Loading branch information
mpusz committed Nov 2, 2024
1 parent 80a4d6b commit 046a832
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
22 changes: 11 additions & 11 deletions src/core/include/mp-units/framework/quantity.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ concept SameValueAs = (equivalent(get_unit(R1), get_unit(R2))) && std::convertib
template<typename T>
using quantity_like_type = quantity<quantity_like_traits<T>::reference, typename quantity_like_traits<T>::rep>;

template<typename T, typename U>
concept Forwarding = std::derived_from<std::remove_cvref_t<T>, U>;
template<typename T, typename U, typename TT = std::remove_reference_t<T>>
concept Mutable = (!std::is_const_v<TT>) && std::derived_from<TT, U>;

} // namespace detail

Expand Down Expand Up @@ -338,7 +338,7 @@ class quantity {
return ::mp_units::quantity{-numerical_value_is_an_implementation_detail_, reference};
}

template<detail::Forwarding<quantity> Q>
template<detail::Mutable<quantity> Q>
friend constexpr decltype(auto) operator++(Q&& q)
requires requires(rep v) {
{ ++v } -> std::same_as<rep&>;
Expand All @@ -356,7 +356,7 @@ class quantity {
return ::mp_units::quantity{numerical_value_is_an_implementation_detail_++, reference};
}

template<detail::Forwarding<quantity> Q>
template<detail::Mutable<quantity> Q>
friend constexpr decltype(auto) operator--(Q&& q)
requires requires(rep v) {
{ --v } -> std::same_as<rep&>;
Expand All @@ -375,7 +375,7 @@ class quantity {
}

// compound assignment operators
template<detail::Forwarding<quantity> Q, auto R2, typename Rep2>
template<detail::Mutable<quantity> Q, auto R2, typename Rep2>
requires detail::QuantityConvertibleTo<quantity<R2, Rep2>, quantity> && requires(rep a, Rep2 b) {
{ a += b } -> std::same_as<rep&>;
}
Expand All @@ -388,7 +388,7 @@ class quantity {
return std::forward<Q>(lhs);
}

template<detail::Forwarding<quantity> Q, auto R2, typename Rep2>
template<detail::Mutable<quantity> Q, auto R2, typename Rep2>
requires detail::QuantityConvertibleTo<quantity<R2, Rep2>, quantity> && requires(rep a, Rep2 b) {
{ a -= b } -> std::same_as<rep&>;
}
Expand All @@ -401,7 +401,7 @@ class quantity {
return std::forward<Q>(lhs);
}

template<detail::Forwarding<quantity> Q, auto R2, typename Rep2>
template<detail::Mutable<quantity> Q, auto R2, typename Rep2>
requires detail::QuantityConvertibleTo<quantity<R2, Rep2>, quantity> && (!treat_as_floating_point<rep>) &&
requires(rep a, Rep2 b) {
{ a %= b } -> std::same_as<rep&>;
Expand All @@ -417,7 +417,7 @@ class quantity {
return std::forward<Q>(lhs);
}

template<detail::Forwarding<quantity> Q, detail::ValuePreservingTo<Rep> Value>
template<detail::Mutable<quantity> Q, detail::ValuePreservingTo<Rep> Value>
requires(!Quantity<Value>) && requires(rep a, Value b) {
{ a *= b } -> std::same_as<rep&>;
}
Expand All @@ -429,7 +429,7 @@ class quantity {
return std::forward<Q>(lhs);
}

template<detail::Forwarding<quantity> Q1, QuantityOf<dimensionless> Q2>
template<detail::Mutable<quantity> Q1, QuantityOf<dimensionless> Q2>
requires(Q2::unit == ::mp_units::one) && detail::ValuePreservingTo<typename Q2::rep, Rep> &&
requires(rep a, Q2::rep b) {
{ a *= b } -> std::same_as<rep&>;
Expand All @@ -439,7 +439,7 @@ class quantity {
return std::forward<Q1>(lhs) *= rhs.numerical_value_is_an_implementation_detail_;
}

template<detail::Forwarding<quantity> Q, detail::ValuePreservingTo<Rep> Value>
template<detail::Mutable<quantity> Q, detail::ValuePreservingTo<Rep> Value>
requires(!Quantity<Value>) && requires(rep a, Value b) {
{ a /= b } -> std::same_as<rep&>;
}
Expand All @@ -452,7 +452,7 @@ class quantity {
return std::forward<Q>(lhs);
}

template<detail::Forwarding<quantity> Q1, QuantityOf<dimensionless> Q2>
template<detail::Mutable<quantity> Q1, QuantityOf<dimensionless> Q2>
requires(Q2::unit == ::mp_units::one) && detail::ValuePreservingTo<typename Q2::rep, Rep> &&
requires(rep a, Q2::rep b) {
{ a /= b } -> std::same_as<rep&>;
Expand Down
8 changes: 4 additions & 4 deletions src/core/include/mp-units/framework/quantity_point.h
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ class quantity_point {
}

// member unary operators
template<detail::Forwarding<quantity_point> QP>
template<detail::Mutable<quantity_point> QP>
friend constexpr decltype(auto) operator++(QP&& qp)
requires requires { ++qp.quantity_from_origin_is_an_implementation_detail_; }
{
Expand All @@ -416,7 +416,7 @@ class quantity_point {
return {quantity_from_origin_is_an_implementation_detail_++, PO};
}

template<detail::Forwarding<quantity_point> QP>
template<detail::Mutable<quantity_point> QP>
friend constexpr decltype(auto) operator--(QP&& qp)
requires requires { --qp.quantity_from_origin_is_an_implementation_detail_; }
{
Expand All @@ -431,15 +431,15 @@ class quantity_point {
}

// compound assignment operators
template<detail::Forwarding<quantity_point> QP>
template<detail::Mutable<quantity_point> QP>
requires requires(quantity_type q) { quantity_from_origin_is_an_implementation_detail_ += q; }
friend constexpr decltype(auto) operator+=(QP&& qp, const quantity_type& q)
{
qp.quantity_from_origin_is_an_implementation_detail_ += q;
return std::forward<QP>(qp);
}

template<detail::Forwarding<quantity_point> QP>
template<detail::Mutable<quantity_point> QP>
requires requires(quantity_type q) { quantity_from_origin_is_an_implementation_detail_ -= q; }
friend constexpr decltype(auto) operator-=(QP&& qp, const quantity_type& q)
{
Expand Down

0 comments on commit 046a832

Please sign in to comment.