From b83008cd24e45e7b8f4f56719e3c75d78ae9e421 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Sun, 24 Nov 2024 10:42:36 +0100 Subject: [PATCH] refactor: `SameQuantitySpec` concept removed and replaced with direct comparison --- src/core/include/mp-units/framework/quantity_spec.h | 2 +- .../mp-units/framework/quantity_spec_concepts.h | 6 +----- src/core/include/mp-units/framework/unit_concepts.h | 10 +++++----- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/core/include/mp-units/framework/quantity_spec.h b/src/core/include/mp-units/framework/quantity_spec.h index 3ca46da2..6226cdde 100644 --- a/src/core/include/mp-units/framework/quantity_spec.h +++ b/src/core/include/mp-units/framework/quantity_spec.h @@ -508,7 +508,7 @@ template } // namespace detail template - requires(!detail::QuantityKindSpec) && detail::SameQuantitySpec + requires(!detail::QuantityKindSpec) && (detail::get_kind_tree_root(Q{}) == Q{}) #if MP_UNITS_API_NO_CRTP struct kind_of_ final : Q::_base_type_ { #else 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 d59229bc..02caaa47 100644 --- a/src/core/include/mp-units/framework/quantity_spec_concepts.h +++ b/src/core/include/mp-units/framework/quantity_spec_concepts.h @@ -105,10 +105,6 @@ MP_UNITS_EXPORT template namespace detail { -template -concept SameQuantitySpec = QuantitySpec && - QuantitySpec && (QS1 == QS2); - template [[nodiscard]] consteval bool is_child_of(Child ch, Parent p); @@ -118,7 +114,7 @@ concept ChildQuantitySpecOf = (is_child_of(Child, Parent)); template concept NestedQuantityKindSpecOf = QuantitySpec && QuantitySpec && - (!SameQuantitySpec) && ChildQuantitySpecOf; + (get_kind(From) != get_kind(To)) && ChildQuantitySpecOf; template concept QuantitySpecConvertibleTo = diff --git a/src/core/include/mp-units/framework/unit_concepts.h b/src/core/include/mp-units/framework/unit_concepts.h index 08984c48..b9c96866 100644 --- a/src/core/include/mp-units/framework/unit_concepts.h +++ b/src/core/include/mp-units/framework/unit_concepts.h @@ -104,11 +104,11 @@ concept AssociatedUnit = Unit && detail::has_associated_quantity(U{}); * the provided quantity_spec type. */ MP_UNITS_EXPORT template -concept UnitOf = AssociatedUnit && QuantitySpec && - detail::QuantitySpecConvertibleTo && - // the below is to make `dimensionless[radian]` invalid - (detail::SameQuantitySpec || - !detail::NestedQuantityKindSpecOf); +concept UnitOf = + AssociatedUnit && QuantitySpec && + detail::QuantitySpecConvertibleTo && + // the below is to make `dimensionless[radian]` invalid + (get_kind(QS) == get_kind(get_quantity_spec(U{})) || !detail::NestedQuantityKindSpecOf); MP_UNITS_EXPORT template [[nodiscard]] consteval bool convertible(From from, To to);