refactor!: require explicit number for references
Addresses: - https://github.com/mpusz/units/pull/261#discussion_r596651065 - https://github.com/mpusz/units/pull/261#discussion_r596664550 - https://github.com/mpusz/units/pull/261#discussion_r597132294
This commit is contained in:
1 parent
6d9abe97e5
commit
0b87e7c99c
8 files changed
+80
-83
No files matched your search
@@ -404,14 +404,10 @@ template<Quantity Q1, QuantityEquivalentTo<Q1> Q2>
|
||||
return ret(ret(lhs).count() - ret(rhs).count());
|
||||
}
|
||||
|
||||
template<typename QuantityOrQuantityValue, typename D, typename U>
|
||||
requires Quantity<QuantityOrQuantityValue> || QuantityValue<QuantityOrQuantityValue>
|
||||
[[nodiscard]] constexpr Quantity auto operator*(const QuantityOrQuantityValue& lhs, reference<D, U>)
|
||||
template<QuantityValue Rep, typename D, typename U>
|
||||
[[nodiscard]] constexpr Quantity auto operator*(const Rep& lhs, reference<D, U>)
|
||||
{
|
||||
if constexpr (Quantity<QuantityOrQuantityValue>)
|
||||
return lhs * quantity<D, U, typename QuantityOrQuantityValue::rep>::one();
|
||||
else
|
||||
return quantity<D, U, QuantityOrQuantityValue>(lhs);
|
||||
return quantity<D, U, Rep>(lhs);
|
||||
}
|
||||
|
||||
template<Quantity Q1, Quantity Q2>
|
||||
@@ -421,14 +417,10 @@ template<Quantity Q1, Quantity Q2>
|
||||
return detail::make_quantity<Q1::reference * Q2::reference>(lhs.count() * rhs.count());
|
||||
}
|
||||
|
||||
template<typename QuantityOrQuantityValue, typename D, typename U>
|
||||
requires Quantity<QuantityOrQuantityValue> || QuantityValue<QuantityOrQuantityValue>
|
||||
[[nodiscard]] constexpr Quantity auto operator/(const QuantityOrQuantityValue& lhs, reference<D, U>)
|
||||
template<QuantityValue Rep, typename D, typename U>
|
||||
[[nodiscard]] constexpr Quantity auto operator/(const Rep& lhs, reference<D, U>)
|
||||
{
|
||||
if constexpr (Quantity<QuantityOrQuantityValue>)
|
||||
return lhs / quantity<D, U, typename QuantityOrQuantityValue::rep>::one();
|
||||
else
|
||||
return lhs / quantity<D, U, QuantityOrQuantityValue>::one();
|
||||
return lhs / quantity<D, U, Rep>::one();
|
||||
}
|
||||
|
||||
template<Quantity Q1, Quantity Q2>
|
||||
|
||||
@@ -72,7 +72,7 @@ using reference_divide = detail::reference_divide_impl<
|
||||
* using namespace units::isq::si::references;
|
||||
*
|
||||
* auto d = 123 * m;
|
||||
* auto v = 70 * km / h;
|
||||
* auto v = 70 * (km / h);
|
||||
* @endcode
|
||||
*
|
||||
* Also, it is allowed to define custom quantity references from existing ones:
|
||||
@@ -89,15 +89,19 @@ struct reference {
|
||||
using dimension = D;
|
||||
using unit = U;
|
||||
|
||||
#if !UNITS_COMP_MSVC
|
||||
template<typename QuantityOrQuantityValue, typename D2, typename U2>
|
||||
requires Quantity<QuantityOrQuantityValue> || QuantityValue<QuantityOrQuantityValue>
|
||||
friend constexpr Quantity auto operator*(const QuantityOrQuantityValue& lhs, reference<D2, U2>);
|
||||
// Hidden Friends
|
||||
// Below friend functions are to be found via argument-dependent lookup only
|
||||
|
||||
template<typename QuantityOrQuantityValue, typename D2, typename U2>
|
||||
requires Quantity<QuantityOrQuantityValue> || QuantityValue<QuantityOrQuantityValue>
|
||||
friend constexpr Quantity auto operator/(const QuantityOrQuantityValue& lhs, reference<D2, U2>);
|
||||
#if !UNITS_COMP_MSVC
|
||||
template<QuantityValue Rep, typename D2, typename U2>
|
||||
friend constexpr Quantity auto operator*(const Rep& lhs, reference<D2, U2>);
|
||||
|
||||
template<QuantityValue Rep, typename D2, typename U2>
|
||||
friend constexpr Quantity auto operator/(const Rep& lhs, reference<D2, U2>);
|
||||
#endif
|
||||
|
||||
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>
|
||||
|
||||
Reference in new issue
Block a user