From 3d6e50c67a13d111b05957166c9b56b001cfae2b Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Sun, 30 Jun 2024 12:06:26 +0200 Subject: [PATCH] refactor: `UnitCompatibleWith` is now exposition-only --- docs/users_guide/framework_basics/concepts.md | 10 ---------- src/core/include/mp-units/framework/quantity.h | 8 ++++---- src/core/include/mp-units/framework/quantity_point.h | 4 ++-- src/core/include/mp-units/framework/unit_concepts.h | 6 +----- 4 files changed, 7 insertions(+), 21 deletions(-) diff --git a/docs/users_guide/framework_basics/concepts.md b/docs/users_guide/framework_basics/concepts.md index da21dcd5..aba062e1 100644 --- a/docs/users_guide/framework_basics/concepts.md +++ b/docs/users_guide/framework_basics/concepts.md @@ -148,16 +148,6 @@ concept with an associated quantity type implicitly convertible to `V`. [nested quantity kind within the dimensionless quantities tree](dimensionless_quantities.md/#nested-quantity-kinds). -### `UnitCompatibleWith` { #UnitCompatibleWith } - -`UnitCompatibleWith` concept is satisfied for all units `T` when: - -- `V1` is a [`Unit`](#Unit), -- `V2` is a [`QuantitySpec`](#QuantitySpec), -- `T` and `V1` are defined in terms of the same reference unit, -- if `T` is an [`AssociatedUnit`](#AssociatedUnit) it should satisfy [`UnitOf`](#UnitOf). - - ## `Reference` { #Reference } `Reference` concept is satisfied by all [quantity reference](../../appendix/glossary.md#reference) diff --git a/src/core/include/mp-units/framework/quantity.h b/src/core/include/mp-units/framework/quantity.h index 69949723..36f5216d 100644 --- a/src/core/include/mp-units/framework/quantity.h +++ b/src/core/include/mp-units/framework/quantity.h @@ -192,14 +192,14 @@ public: quantity& operator=(quantity&&) = default; // unit conversions - template ToU> + template ToU> requires detail::QuantityConvertibleTo> [[nodiscard]] constexpr QuantityOf auto in(ToU) const { return quantity{*this}; } - template ToU> + template ToU> requires requires(quantity q) { value_cast(q); } [[nodiscard]] constexpr QuantityOf auto force_in(ToU) const { @@ -230,14 +230,14 @@ public: = delete; #endif - template U> + template U> requires detail::QuantityConvertibleTo> [[nodiscard]] constexpr rep numerical_value_in(U) const noexcept { return (*this).in(U{}).numerical_value_is_an_implementation_detail_; } - template U> + template U> requires requires(quantity q) { value_cast(q); } [[nodiscard]] constexpr rep force_numerical_value_in(U) const noexcept { diff --git a/src/core/include/mp-units/framework/quantity_point.h b/src/core/include/mp-units/framework/quantity_point.h index a121feb7..fefaa8e9 100644 --- a/src/core/include/mp-units/framework/quantity_point.h +++ b/src/core/include/mp-units/framework/quantity_point.h @@ -277,14 +277,14 @@ public: } // unit conversions - template ToU> + template ToU> requires detail::QuantityConvertibleTo> [[nodiscard]] constexpr QuantityPointOf auto in(ToU) const { return ::mp_units::quantity_point{quantity_ref_from(PO).in(ToU{}), PO}; } - template ToU> + template ToU> requires requires(quantity_type q) { value_cast(q); } [[nodiscard]] constexpr QuantityPointOf auto force_in(ToU) const { diff --git a/src/core/include/mp-units/framework/unit_concepts.h b/src/core/include/mp-units/framework/unit_concepts.h index 3a271e90..e68935be 100644 --- a/src/core/include/mp-units/framework/unit_concepts.h +++ b/src/core/include/mp-units/framework/unit_concepts.h @@ -197,8 +197,6 @@ template concept UnitConvertibleTo = Unit && Unit && (convertible(From, To)); -} // namespace detail - /** * @brief A concept matching all units compatible with the provided unit and quantity spec * @@ -210,11 +208,9 @@ concept UnitCompatibleWith = Unit && Unit && QuantitySpec && (!AssociatedUnit || UnitOf)&&detail::UnitConvertibleTo; -namespace detail { - template concept OffsetUnit = Unit && requires { T::point_origin; }; -} +} // namespace detail } // namespace mp_units