From f81e9bdcfe27ff289bb9212082020365889d5194 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Tue, 20 Feb 2024 19:49:22 +0100 Subject: [PATCH] refactor: `kind_of_` refactored to take a type to improve error messages --- .../mp-units/bits/quantity_spec_concepts.h | 4 +-- src/core/include/mp-units/quantity_spec.h | 28 +++++++++---------- test/static/quantity_spec_test.cpp | 20 ++++++------- 3 files changed, 25 insertions(+), 27 deletions(-) diff --git a/src/core/include/mp-units/bits/quantity_spec_concepts.h b/src/core/include/mp-units/bits/quantity_spec_concepts.h index 9ee2b690..6ddff15c 100644 --- a/src/core/include/mp-units/bits/quantity_spec_concepts.h +++ b/src/core/include/mp-units/bits/quantity_spec_concepts.h @@ -34,7 +34,7 @@ template #endif struct quantity_spec; -template +template struct kind_of_; namespace detail { @@ -42,7 +42,7 @@ namespace detail { template inline constexpr bool is_specialization_of_kind_of = false; -template +template inline constexpr bool is_specialization_of_kind_of> = true; template diff --git a/src/core/include/mp-units/quantity_spec.h b/src/core/include/mp-units/quantity_spec.h index 2b25b8a7..15e87547 100644 --- a/src/core/include/mp-units/quantity_spec.h +++ b/src/core/include/mp-units/quantity_spec.h @@ -450,30 +450,28 @@ template } // namespace detail #ifdef __cpp_explicit_this_parameter -template - requires(detail::QuantitySpecWithNoSpecifiers>) && - (detail::get_kind_tree_root(Q) == Q) -struct kind_of_ : std::remove_const_t { - static constexpr auto _quantity_spec_ = Q; +template + requires detail::QuantitySpecWithNoSpecifiers && (detail::get_kind_tree_root(Q{}) == Q{}) +struct kind_of_ : Q { + static constexpr auto _quantity_spec_ = Q{}; }; #else #if MP_UNITS_COMP_CLANG -template - requires detail::QuantitySpecWithNoSpecifiers> && - (detail::get_kind_tree_root(Q) == Q) +template + requires detail::QuantitySpecWithNoSpecifiers && (detail::get_kind_tree_root(Q{}) == Q{}) #else -template - requires(detail::get_kind_tree_root(Q) == Q) +template + requires(detail::get_kind_tree_root(Q{}) == Q{}) #endif -struct kind_of_ : quantity_spec, Q> { - static constexpr auto _quantity_spec_ = Q; +struct kind_of_ : quantity_spec, Q{}> { + static constexpr auto _quantity_spec_ = Q{}; }; #endif template requires(detail::get_kind_tree_root(Q) == Q) -inline constexpr kind_of_ kind_of; +inline constexpr kind_of_> kind_of; namespace detail { @@ -601,10 +599,10 @@ template return get_complexity(Q{}); } -template +template [[nodiscard]] consteval int get_complexity(kind_of_) { - return get_complexity(Q); + return get_complexity(Q{}); } template diff --git a/test/static/quantity_spec_test.cpp b/test/static/quantity_spec_test.cpp index b845e4c8..a7e7ee65 100644 --- a/test/static/quantity_spec_test.cpp +++ b/test/static/quantity_spec_test.cpp @@ -111,10 +111,10 @@ static_assert(detail::NamedQuantitySpec); static_assert(!detail::IntermediateDerivedQuantitySpec); static_assert(!detail::QuantityKindSpec); -static_assert(QuantitySpec>); -static_assert(!detail::NamedQuantitySpec>); -static_assert(!detail::IntermediateDerivedQuantitySpec>); -static_assert(detail::QuantityKindSpec>); +static_assert(QuantitySpec>); +static_assert(!detail::NamedQuantitySpec>); +static_assert(!detail::IntermediateDerivedQuantitySpec>); +static_assert(detail::QuantityKindSpec>); static_assert(QuantitySpec); static_assert(detail::NamedQuantitySpec); @@ -126,10 +126,10 @@ static_assert(!detail::NamedQuantitySpec); static_assert(detail::IntermediateDerivedQuantitySpec); static_assert(!detail::QuantityKindSpec); -static_assert(QuantitySpec>); -static_assert(!detail::NamedQuantitySpec>); -static_assert(detail::IntermediateDerivedQuantitySpec>); -static_assert(detail::QuantityKindSpec>); +static_assert(QuantitySpec>>); +static_assert(!detail::NamedQuantitySpec>>); +static_assert(detail::IntermediateDerivedQuantitySpec>>); +static_assert(detail::QuantityKindSpec>>); static_assert(QuantitySpec / kind_of