Skip to content

Commit

Permalink
refactor: quantity operators refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
mpusz committed Oct 20, 2023
1 parent 15922b5 commit df26169
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/core/include/mp-units/quantity.h
Original file line number Diff line number Diff line change
Expand Up @@ -450,33 +450,31 @@ template<auto R1, typename Rep1, auto R2, typename Rep2>
requires detail::InvocableQuantities<std::multiplies<>, quantity<R1, Rep1>, quantity<R2, Rep2>>
[[nodiscard]] constexpr Quantity auto operator*(const quantity<R1, Rep1>& lhs, const quantity<R2, Rep2>& rhs)
{
return make_quantity<R1 * R2>(lhs.numerical_value_ref_in(quantity<R1, Rep1>::unit) *
rhs.numerical_value_ref_in(quantity<R2, Rep2>::unit));
return make_quantity<R1 * R2>(lhs.numerical_value_ref_in(get_unit(R1)) * rhs.numerical_value_ref_in(get_unit(R2)));
}

template<auto R, typename Rep, typename Value>
requires(!Quantity<Value>) && (!Reference<Value>) &&
detail::InvokeResultOf<get_quantity_spec(R).character, std::multiplies<>, Rep, const Value&>
[[nodiscard]] constexpr Quantity auto operator*(const quantity<R, Rep>& q, const Value& v)
{
return make_quantity<R>(q.numerical_value_ref_in(quantity<R, Rep>::unit) * v);
return make_quantity<R>(q.numerical_value_ref_in(get_unit(R)) * v);
}

template<typename Value, auto R, typename Rep>
requires(!Quantity<Value>) && (!Reference<Value>) &&
detail::InvokeResultOf<get_quantity_spec(R).character, std::multiplies<>, const Value&, Rep>
[[nodiscard]] constexpr Quantity auto operator*(const Value& v, const quantity<R, Rep>& q)
{
return make_quantity<R>(v * q.numerical_value_ref_in(quantity<R, Rep>::unit));
return make_quantity<R>(v * q.numerical_value_ref_in(get_unit(R)));
}

template<auto R1, typename Rep1, auto R2, typename Rep2>
requires detail::InvocableQuantities<std::divides<>, quantity<R1, Rep1>, quantity<R2, Rep2>>
[[nodiscard]] constexpr Quantity auto operator/(const quantity<R1, Rep1>& lhs, const quantity<R2, Rep2>& rhs)
{
gsl_ExpectsAudit(rhs != rhs.zero());
return make_quantity<R1 / R2>(lhs.numerical_value_ref_in(quantity<R1, Rep1>::unit) /
rhs.numerical_value_ref_in(quantity<R2, Rep2>::unit));
return make_quantity<R1 / R2>(lhs.numerical_value_ref_in(get_unit(R1)) / rhs.numerical_value_ref_in(get_unit(R2)));
}

template<auto R, typename Rep, typename Value>
Expand All @@ -485,15 +483,15 @@ template<auto R, typename Rep, typename Value>
[[nodiscard]] constexpr Quantity auto operator/(const quantity<R, Rep>& q, const Value& v)
{
gsl_ExpectsAudit(v != quantity_values<Value>::zero());
return make_quantity<R>(q.numerical_value_ref_in(quantity<R, Rep>::unit) / v);
return make_quantity<R>(q.numerical_value_ref_in(get_unit(R)) / v);
}

template<typename Value, auto R, typename Rep>
requires(!Quantity<Value>) && (!Reference<Value>) &&
detail::InvokeResultOf<get_quantity_spec(R).character, std::divides<>, const Value&, Rep>
[[nodiscard]] constexpr Quantity auto operator/(const Value& v, const quantity<R, Rep>& q)
{
return make_quantity<::mp_units::one / R>(v / q.numerical_value_ref_in(quantity<R, Rep>::unit));
return make_quantity<::mp_units::one / R>(v / q.numerical_value_ref_in(get_unit(R)));
}

template<auto R1, typename Rep1, auto R2, typename Rep2>
Expand Down

0 comments on commit df26169

Please sign in to comment.