From b96be72457118863cc41c82b941cdec6fb0e5ea4 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Sun, 15 Oct 2023 09:39:18 +0200 Subject: [PATCH] feat: :boom: `quantity_point` does not provide `zero()` anymore --- example/include/geographic.h | 28 +++++++++---------- src/core/include/mp-units/quantity_point.h | 6 ---- test/unit_test/static/quantity_point_test.cpp | 4 --- 3 files changed, 14 insertions(+), 24 deletions(-) diff --git a/example/include/geographic.h b/example/include/geographic.h index b704dd245..d68308963 100644 --- a/example/include/geographic.h +++ b/example/include/geographic.h @@ -79,19 +79,21 @@ using longitude = mp_units::quantity_point std::basic_ostream& operator<<(std::basic_ostream& os, const latitude& lat) { - if (is_gteq_zero(lat)) - return os << lat.quantity_from_origin() << " N"; + const auto& q = lat.quantity_ref_from(geographic::equator); + if (is_gteq_zero(q)) + return os << q << " N"; else - return os << -lat.quantity_from_origin() << " S"; + return os << -q << " S"; } template std::basic_ostream& operator<<(std::basic_ostream& os, const longitude& lon) { - if (is_gteq_zero(lon)) - return os << lon.quantity_from_origin() << " E"; + const auto& q = lon.quantity_ref_from(geographic::prime_meridian); + if (is_gteq_zero(q)) + return os << q << " E"; else - return os << -lon.quantity_from_origin() << " W"; + return os << -q << " W"; } inline namespace literals { @@ -137,9 +139,9 @@ struct MP_UNITS_STD_FMT::formatter> : template auto format(geographic::latitude lat, FormatContext& ctx) { - formatter::quantity_type>::format( - is_gteq_zero(lat) ? lat.quantity_from(geographic::equator) : -lat.quantity_from(geographic::equator), ctx); - MP_UNITS_STD_FMT::format_to(ctx.out(), "{}", is_gteq_zero(lat) ? " N" : "S"); + const auto& q = lat.quantity_ref_from(geographic::equator); + formatter::quantity_type>::format(is_gteq_zero(q) ? q : -q, ctx); + MP_UNITS_STD_FMT::format_to(ctx.out(), "{}", is_gteq_zero(q) ? " N" : "S"); return ctx.out(); } }; @@ -150,11 +152,9 @@ struct MP_UNITS_STD_FMT::formatter> : template auto format(geographic::longitude lon, FormatContext& ctx) { - formatter::quantity_type>::format( - is_gteq_zero(lon) ? lon.quantity_from(geographic::prime_meridian) - : -lon.quantity_from(geographic::prime_meridian), - ctx); - MP_UNITS_STD_FMT::format_to(ctx.out(), "{}", is_gteq_zero(lon) ? " E" : " W"); + const auto& q = lon.quantity_ref_from(geographic::prime_meridian); + formatter::quantity_type>::format(is_gteq_zero(q) ? q : -q, ctx); + MP_UNITS_STD_FMT::format_to(ctx.out(), "{}", is_gteq_zero(q) ? " E" : " W"); return ctx.out(); } }; diff --git a/src/core/include/mp-units/quantity_point.h b/src/core/include/mp-units/quantity_point.h index 6cf8308bd..9d71c3c54 100644 --- a/src/core/include/mp-units/quantity_point.h +++ b/src/core/include/mp-units/quantity_point.h @@ -85,12 +85,6 @@ class quantity_point { quantity_type quantity_from_origin_; // needs to be public for a structural type // static member functions - [[nodiscard]] static constexpr quantity_point zero() noexcept - requires requires { quantity_type::zero(); } - { - return quantity_point(quantity_type::zero()); - } - [[nodiscard]] static constexpr quantity_point min() noexcept requires requires { quantity_type::min(); } { diff --git a/test/unit_test/static/quantity_point_test.cpp b/test/unit_test/static/quantity_point_test.cpp index 46e0b6d11..0368f30ba 100644 --- a/test/unit_test/static/quantity_point_test.cpp +++ b/test/unit_test/static/quantity_point_test.cpp @@ -240,15 +240,11 @@ static_assert( // static member functions //////////////////////////// -static_assert(quantity_point::zero().quantity_from_origin_.numerical_value_ == 0); static_assert(quantity_point::min().quantity_from_origin_.numerical_value_ == std::numeric_limits::lowest()); static_assert(quantity_point::max().quantity_from_origin_.numerical_value_ == std::numeric_limits::max()); -static_assert( - - quantity_point::zero().quantity_from_origin_.numerical_value_ == 0); static_assert(quantity_point::min().quantity_from_origin_.numerical_value_ == std::numeric_limits::lowest()); static_assert(quantity_point::max().quantity_from_origin_.numerical_value_ ==