From 1068f7d182bf517781e4ef3c9540afd3b8804d87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johel=20Ernesto=20Guerrero=20Pe=C3=B1a?= Date: Thu, 18 Mar 2021 13:40:49 -0400 Subject: [PATCH] refactor: use values rather than types for reference Addresses https://github.com/mpusz/units/pull/261#discussion_r596661260. --- src/core/include/units/quantity.h | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/core/include/units/quantity.h b/src/core/include/units/quantity.h index c7f8b071..c47635ce 100644 --- a/src/core/include/units/quantity.h +++ b/src/core/include/units/quantity.h @@ -36,10 +36,10 @@ namespace units { namespace detail { -template // TODO: Replace with `v * R{}` pending https://github.com/BobSteagall/wg21/issues/58. +template // TODO: Replace with `v * R{}` pending https://github.com/BobSteagall/wg21/issues/58. inline constexpr auto make_quantity = [](auto v) { using Rep = decltype(v); - return quantity(std::move(v)); + return quantity(std::move(v)); }; } // namespace detail @@ -108,11 +108,11 @@ template U, QuantityValue Rep = double> class quantity { Rep value_; public: - // member types - using reference = units::reference; + // member types and values using dimension = D; using unit = U; using rep = Rep; + static constexpr units::reference reference{}; // static member functions [[nodiscard]] static constexpr quantity zero() noexcept @@ -418,8 +418,7 @@ template requires quantity_value_for_, typename Q1::rep, typename Q2::rep> [[nodiscard]] constexpr Quantity auto operator*(const Q1& lhs, const Q2& rhs) { - return detail::make_quantity>( - lhs.count() * rhs.count()); + return detail::make_quantity(lhs.count() * rhs.count()); } template @@ -437,8 +436,7 @@ template [[nodiscard]] constexpr Quantity auto operator/(const Q1& lhs, const Q2& rhs) { gsl_ExpectsAudit(rhs.count() != quantity_values::zero()); - return detail::make_quantity>( - lhs.count() / rhs.count()); + return detail::make_quantity(lhs.count() / rhs.count()); } template