forked from mpusz/mp-units
refactor: use values rather than types for reference
Addresses https://github.com/mpusz/units/pull/261#discussion_r596661260.
This commit is contained in:
committed by
Mateusz Pusz
parent
4622979ed9
commit
1068f7d182
@@ -36,10 +36,10 @@ namespace units {
|
|||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
|
||||||
template<Reference R> // TODO: Replace with `v * R{}` pending https://github.com/BobSteagall/wg21/issues/58.
|
template<Reference auto R> // TODO: Replace with `v * R{}` pending https://github.com/BobSteagall/wg21/issues/58.
|
||||||
inline constexpr auto make_quantity = [](auto v) {
|
inline constexpr auto make_quantity = [](auto v) {
|
||||||
using Rep = decltype(v);
|
using Rep = decltype(v);
|
||||||
return quantity<typename R::dimension, typename R::unit, Rep>(std::move(v));
|
return quantity<typename decltype(R)::dimension, typename decltype(R)::unit, Rep>(std::move(v));
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
@@ -108,11 +108,11 @@ template<Dimension D, UnitOf<D> U, QuantityValue Rep = double>
|
|||||||
class quantity {
|
class quantity {
|
||||||
Rep value_;
|
Rep value_;
|
||||||
public:
|
public:
|
||||||
// member types
|
// member types and values
|
||||||
using reference = units::reference<D, U>;
|
|
||||||
using dimension = D;
|
using dimension = D;
|
||||||
using unit = U;
|
using unit = U;
|
||||||
using rep = Rep;
|
using rep = Rep;
|
||||||
|
static constexpr units::reference<D, U> reference{};
|
||||||
|
|
||||||
// static member functions
|
// static member functions
|
||||||
[[nodiscard]] static constexpr quantity zero() noexcept
|
[[nodiscard]] static constexpr quantity zero() noexcept
|
||||||
@@ -418,8 +418,7 @@ template<Quantity Q1, Quantity Q2>
|
|||||||
requires quantity_value_for_<std::multiplies<>, typename Q1::rep, typename Q2::rep>
|
requires quantity_value_for_<std::multiplies<>, typename Q1::rep, typename Q2::rep>
|
||||||
[[nodiscard]] constexpr Quantity auto operator*(const Q1& lhs, const Q2& rhs)
|
[[nodiscard]] constexpr Quantity auto operator*(const Q1& lhs, const Q2& rhs)
|
||||||
{
|
{
|
||||||
return detail::make_quantity<reference_multiply<typename Q1::reference, typename Q2::reference>>(
|
return detail::make_quantity<Q1::reference * Q2::reference>(lhs.count() * rhs.count());
|
||||||
lhs.count() * rhs.count());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename QuantityOrQuantityValue, typename D, typename U>
|
template<typename QuantityOrQuantityValue, typename D, typename U>
|
||||||
@@ -437,8 +436,7 @@ template<Quantity Q1, Quantity Q2>
|
|||||||
[[nodiscard]] constexpr Quantity auto operator/(const Q1& lhs, const Q2& rhs)
|
[[nodiscard]] constexpr Quantity auto operator/(const Q1& lhs, const Q2& rhs)
|
||||||
{
|
{
|
||||||
gsl_ExpectsAudit(rhs.count() != quantity_values<typename Q2::rep>::zero());
|
gsl_ExpectsAudit(rhs.count() != quantity_values<typename Q2::rep>::zero());
|
||||||
return detail::make_quantity<reference_divide<typename Q1::reference, typename Q2::reference>>(
|
return detail::make_quantity<Q1::reference / Q2::reference>(lhs.count() / rhs.count());
|
||||||
lhs.count() / rhs.count());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename D1, typename U1, typename Rep1, typename U2, typename Rep2>
|
template<typename D1, typename U1, typename Rep1, typename U2, typename Rep2>
|
||||||
|
Reference in New Issue
Block a user