From b685521a183370966f9622ac5918beaaa47f541b Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Sat, 28 Dec 2024 13:52:24 +0100 Subject: [PATCH] Revert "refactor: `QuantitySpec` convertibility concepts replaced with direct function calls" This reverts commit 09488409d24f3a117c89fd51044e6f1242d87c62. --- src/core/include/mp-units/framework/quantity.h | 2 +- .../include/mp-units/framework/quantity_cast.h | 4 ++-- .../include/mp-units/framework/quantity_spec.h | 14 +++++++------- .../mp-units/framework/quantity_spec_concepts.h | 2 +- .../include/mp-units/framework/unit_concepts.h | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/core/include/mp-units/framework/quantity.h b/src/core/include/mp-units/framework/quantity.h index 5164c672..8f4b4ef3 100644 --- a/src/core/include/mp-units/framework/quantity.h +++ b/src/core/include/mp-units/framework/quantity.h @@ -71,7 +71,7 @@ concept ValuePreservingTo = Representation> && Repr template concept QuantityConvertibleTo = - Quantity && Quantity && implicitly_convertible(QFrom::quantity_spec, QTo::quantity_spec) && + Quantity && Quantity && QuantitySpecConvertibleTo && UnitConvertibleTo && ValuePreservingTo && // TODO consider providing constraints of sudo_cast here rather than testing if it can be called (its return type is diff --git a/src/core/include/mp-units/framework/quantity_cast.h b/src/core/include/mp-units/framework/quantity_cast.h index 949ee3cd..ba28d193 100644 --- a/src/core/include/mp-units/framework/quantity_cast.h +++ b/src/core/include/mp-units/framework/quantity_cast.h @@ -57,7 +57,7 @@ namespace mp_units { * @tparam ToQS a quantity specification to use for a target quantity */ template> - requires(castable(Q::quantity_spec, ToQS)) + requires detail::QuantitySpecCastableTo [[nodiscard]] constexpr Quantity auto quantity_cast(FwdQ&& q) { return quantity{std::forward(q).numerical_value_is_an_implementation_detail_, make_reference(ToQS, Q::unit)}; @@ -81,7 +81,7 @@ template> - requires(castable(QP::quantity_spec, ToQS)) + requires detail::QuantitySpecCastableTo [[nodiscard]] constexpr QuantityPoint auto quantity_cast(FwdQP&& qp) { return QP{quantity_cast(std::forward(qp).quantity_from_origin_is_an_implementation_detail_), diff --git a/src/core/include/mp-units/framework/quantity_spec.h b/src/core/include/mp-units/framework/quantity_spec.h index 4e524519..e7f1b7c2 100644 --- a/src/core/include/mp-units/framework/quantity_spec.h +++ b/src/core/include/mp-units/framework/quantity_spec.h @@ -151,7 +151,7 @@ struct quantity_spec_interface : quantity_spec_interface_base { } template> - requires(explicitly_convertible(Q::quantity_spec, Self{})) + requires QuantitySpecExplicitlyConvertibleTo [[nodiscard]] constexpr Quantity auto operator()(this Self self, FwdQ&& q) { return quantity{std::forward(q).numerical_value_is_an_implementation_detail_, make_reference(self, Q::unit)}; @@ -164,7 +164,7 @@ struct quantity_spec_interface : quantity_spec_interface_base { } template, typename Self_ = Self> - requires(explicitly_convertible(Q::quantity_spec, Self_{})) + requires QuantitySpecExplicitlyConvertibleTo [[nodiscard]] constexpr Quantity auto operator()(FwdQ&& q) const { return quantity{std::forward(q).numerical_value_is_an_implementation_detail_, @@ -357,7 +357,7 @@ struct quantity_spec : detail::propagate_equation, detail } template, typename Self_ = Self> - requires(explicitly_convertible(Q::quantity_spec, Self_{})) + requires detail::QuantitySpecExplicitlyConvertibleTo [[nodiscard]] constexpr Quantity auto operator()(FwdQ&& q) const { return quantity{std::forward(q).numerical_value_is_an_implementation_detail_, @@ -398,12 +398,12 @@ struct quantity_spec : detail::propagate_equation, detail // clang-format on #if MP_UNITS_API_NO_CRTP template - requires(explicitly_convertible(Eq, QS)) + requires(detail::QuantitySpecExplicitlyConvertibleTo) struct quantity_spec : detail::quantity_spec_interface { #else template - requires(explicitly_convertible(Eq, QS)) + requires(detail::QuantitySpecExplicitlyConvertibleTo) struct quantity_spec : detail::quantity_spec_interface { #endif using _base_type_ = quantity_spec; @@ -1547,8 +1547,8 @@ template [[nodiscard]] consteval QuantitySpec auto get_common_quantity_spec(QuantitySpec auto q) { return q; } template - requires(implicitly_convertible(detail::get_kind_tree_root(Q1{}), detail::get_kind_tree_root(Q2{}))) || - (implicitly_convertible(detail::get_kind_tree_root(Q2{}), detail::get_kind_tree_root(Q1{}))) + requires detail::QuantitySpecConvertibleTo || + detail::QuantitySpecConvertibleTo [[nodiscard]] consteval QuantitySpec auto get_common_quantity_spec(Q1 q1, Q2 q2) { using QQ1 = decltype(detail::remove_kind(q1)); diff --git a/src/core/include/mp-units/framework/quantity_spec_concepts.h b/src/core/include/mp-units/framework/quantity_spec_concepts.h index 521ffeae..110e52eb 100644 --- a/src/core/include/mp-units/framework/quantity_spec_concepts.h +++ b/src/core/include/mp-units/framework/quantity_spec_concepts.h @@ -134,7 +134,7 @@ concept QuantitySpecCastableTo = QuantitySpec concept QuantitySpecOf = - QuantitySpec && QuantitySpec && (implicitly_convertible(T{}, QS)) && + QuantitySpec && QuantitySpec && detail::QuantitySpecConvertibleTo && // the below is to make the following work // static_assert(ReferenceOf); // static_assert(!ReferenceOf); diff --git a/src/core/include/mp-units/framework/unit_concepts.h b/src/core/include/mp-units/framework/unit_concepts.h index d7933c35..86ff5e28 100644 --- a/src/core/include/mp-units/framework/unit_concepts.h +++ b/src/core/include/mp-units/framework/unit_concepts.h @@ -106,7 +106,7 @@ concept AssociatedUnit = Unit && detail::has_associated_quantity(U{}); MP_UNITS_EXPORT template concept UnitOf = AssociatedUnit && QuantitySpec && - (implicitly_convertible(get_quantity_spec(U{}), QS)) && + detail::QuantitySpecConvertibleTo && // the below is to make `dimensionless[radian]` invalid (get_kind(QS) == get_kind(get_quantity_spec(U{})) || !detail::NestedQuantityKindSpecOf);