From a3e5c84a4750dc265c886af19d98dccb2d6d530a Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Wed, 24 May 2023 22:39:42 +0200 Subject: [PATCH] feat: support for convertibility of point origins added --- example/include/geographic.h | 6 +++--- example/unmanned_aerial_vehicle.cpp | 1 + src/core/include/mp_units/bits/quantity_point_concepts.h | 2 +- src/core/include/mp_units/quantity_point.h | 7 ++++++- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/example/include/geographic.h b/example/include/geographic.h index b3268393..1c514cde 100644 --- a/example/include/geographic.h +++ b/example/include/geographic.h @@ -37,9 +37,9 @@ namespace geographic { -// clang-format off -inline constexpr struct mean_sea_level : mp_units::absolute_point_origin {} mean_sea_level; -// clang-format on +inline constexpr struct mean_sea_level : mp_units::absolute_point_origin { + using mp_units::absolute_point_origin::absolute_point_origin; +} mean_sea_level; using msl_altitude = mp_units::quantity_point; diff --git a/example/unmanned_aerial_vehicle.cpp b/example/unmanned_aerial_vehicle.cpp index 31f41e84..f8dee6d6 100644 --- a/example/unmanned_aerial_vehicle.cpp +++ b/example/unmanned_aerial_vehicle.cpp @@ -38,6 +38,7 @@ enum class earth_gravity_model { egm84_15, egm95_5, egm2008_1 }; template struct height_above_ellipsoid_t : absolute_point_origin { static constexpr earth_gravity_model egm = M; + using absolute_point_origin::absolute_point_origin; }; template inline constexpr height_above_ellipsoid_t height_above_ellipsoid; diff --git a/src/core/include/mp_units/bits/quantity_point_concepts.h b/src/core/include/mp_units/bits/quantity_point_concepts.h index 3f20b08f..197a9da8 100644 --- a/src/core/include/mp_units/bits/quantity_point_concepts.h +++ b/src/core/include/mp_units/bits/quantity_point_concepts.h @@ -98,7 +98,7 @@ concept QuantityPointOf = QuantityPoint && (ReferenceOf, V> || (PointOrigin> && - std::same_as, std::remove_const_t>)); + std::convertible_to, std::remove_const_t>)); /** * @brief A concept matching all external quantity point like types diff --git a/src/core/include/mp_units/quantity_point.h b/src/core/include/mp_units/quantity_point.h index 59c574c6..d9077e04 100644 --- a/src/core/include/mp_units/quantity_point.h +++ b/src/core/include/mp_units/quantity_point.h @@ -1,4 +1,3 @@ - // The MIT License (MIT) // // Copyright (c) 2018 Mateusz Pusz @@ -33,6 +32,12 @@ namespace mp_units { template struct absolute_point_origin { static constexpr QuantitySpec auto quantity_spec = Q; + absolute_point_origin() = default; + template + requires(implicitly_convertible(Q2, Q)) + consteval absolute_point_origin(absolute_point_origin) + { + } }; namespace detail {