mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-05 05:04:27 +02:00
refactor: make reference's interface hidden friends
Addresses: - https://github.com/mpusz/units/pull/261#discussion_r597135187 - https://github.com/mpusz/units/pull/261#discussion_r597152408
This commit is contained in:
committed by
Mateusz Pusz
parent
234337d310
commit
ced4b3bbed
@@ -404,12 +404,6 @@ template<Quantity Q1, QuantityEquivalentTo<Q1> Q2>
|
||||
return ret(ret(lhs).count() - ret(rhs).count());
|
||||
}
|
||||
|
||||
template<QuantityValue Rep, typename D, typename U>
|
||||
[[nodiscard]] constexpr Quantity auto operator*(const Rep& lhs, reference<D, U>)
|
||||
{
|
||||
return quantity<D, U, Rep>(lhs);
|
||||
}
|
||||
|
||||
template<Quantity Q1, Quantity Q2>
|
||||
requires quantity_value_for_<std::multiplies<>, typename Q1::rep, typename Q2::rep>
|
||||
[[nodiscard]] constexpr Quantity auto operator*(const Q1& lhs, const Q2& rhs)
|
||||
@@ -417,12 +411,6 @@ template<Quantity Q1, Quantity Q2>
|
||||
return detail::make_quantity<Q1::reference * Q2::reference>(lhs.count() * rhs.count());
|
||||
}
|
||||
|
||||
template<QuantityValue Rep, typename D, typename U>
|
||||
[[nodiscard]] constexpr Quantity auto operator/(const Rep& lhs, reference<D, U>)
|
||||
{
|
||||
return lhs / quantity<D, U, Rep>::one();
|
||||
}
|
||||
|
||||
template<Quantity Q1, Quantity Q2>
|
||||
requires quantity_value_for_<std::divides<>, typename Q1::rep, typename Q2::rep>
|
||||
[[nodiscard]] constexpr Quantity auto operator/(const Q1& lhs, const Q2& rhs)
|
||||
|
@@ -27,6 +27,9 @@
|
||||
|
||||
namespace units {
|
||||
|
||||
template<Dimension D, UnitOf<D> U, QuantityValue Rep>
|
||||
class quantity;
|
||||
|
||||
template<Dimension D, UnitOf<D> U>
|
||||
struct reference;
|
||||
|
||||
@@ -92,24 +95,28 @@ struct reference {
|
||||
// Hidden Friends
|
||||
// Below friend functions are to be found via argument-dependent lookup only
|
||||
|
||||
#if !UNITS_COMP_MSVC
|
||||
template<QuantityValue Rep, typename D2, typename U2>
|
||||
friend constexpr Quantity auto operator*(const Rep& lhs, reference<D2, U2>);
|
||||
template<Reference R2>
|
||||
[[nodiscard]] friend constexpr reference_multiply<reference, R2> operator*(reference, R2) { return {}; }
|
||||
|
||||
template<QuantityValue Rep, typename D2, typename U2>
|
||||
friend constexpr Quantity auto operator/(const Rep& lhs, reference<D2, U2>);
|
||||
#endif
|
||||
template<Reference R2>
|
||||
[[nodiscard]] friend constexpr reference_divide<reference, R2> operator/(reference, R2) { return {}; }
|
||||
|
||||
template<QuantityValue Rep>
|
||||
[[nodiscard]] friend constexpr Quantity auto operator*(const Rep& lhs, reference)
|
||||
{
|
||||
return quantity<D, U, Rep>(lhs);
|
||||
}
|
||||
|
||||
template<QuantityValue Rep>
|
||||
[[nodiscard]] friend constexpr Quantity auto operator/(const Rep& lhs, reference)
|
||||
{
|
||||
return lhs / quantity<D, U, Rep>::one();
|
||||
}
|
||||
|
||||
friend void /*Use `q * (1 * r)` rather than `q * r`.*/ operator*(Quantity auto, reference) = delete;
|
||||
friend void /*Use `q / (1 * r)` rather than `q / r`.*/ operator/(Quantity auto, reference) = delete;
|
||||
};
|
||||
|
||||
template<Reference R1, Reference R2>
|
||||
[[nodiscard]] constexpr reference_multiply<R1, R2> operator*(R1, R2) { return {}; }
|
||||
|
||||
template<Reference R1, Reference R2>
|
||||
[[nodiscard]] constexpr reference_divide<R1, R2> operator/(R1, R2) { return {}; }
|
||||
|
||||
// type traits
|
||||
namespace detail {
|
||||
|
||||
|
Reference in New Issue
Block a user