From 89756c5b74fafa79c267785af68b92268d1af94d Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Mon, 13 Feb 2023 18:35:07 +0100 Subject: [PATCH] feat: `QuantityKindSpec` concept support added + some cleanup --- .../mp_units/bits/quantity_spec_concepts.h | 45 ++++++++++++++++++- 1 file changed, 43 insertions(+), 2 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 00e16e89..beb2d7e6 100644 --- a/src/core/include/mp_units/bits/quantity_spec_concepts.h +++ b/src/core/include/mp_units/bits/quantity_spec_concepts.h @@ -120,13 +120,54 @@ namespace detail { * @brief Concept matching all derived quantity specification types * * Satisfied by all `derived_quantity_spec` specializations. + * + * @note Deriving a strong type from it is considered a logic error and thus is + * explicitly not supported here. */ template -concept DerivedQuantitySpec = is_derived_from_specialization_of; +concept IntermediateDerivedQuantitySpec = is_specialization_of; } // namespace detail template -concept QuantitySpec = detail::NamedQuantitySpec || detail::DerivedQuantitySpec; +concept QuantitySpec = detail::NamedQuantitySpec || detail::IntermediateDerivedQuantitySpec; +namespace detail { + +template +inline constexpr bool is_quantity_spec_with_no_specifiers = false; + +template +concept QuantitySpecWithNoSpecifiers = is_quantity_spec_with_no_specifiers; + +} // namespace detail + +template +[[nodiscard]] consteval QuantitySpec auto get_kind(Q q); + +template + requires(get_kind(Q) == Q) +struct kind_of_; + +namespace detail { + +template +void to_base_specialization_of_kind_of(const volatile kind_of_*); + +template +inline constexpr bool is_derived_from_specialization_of_kind_of = + requires(T* t) { to_base_specialization_of_kind_of(t); }; + +} // namespace detail + +template +concept QuantityKindSpec = QuantitySpec && detail::is_derived_from_specialization_of_kind_of; + +namespace detail { + +template + requires QuantitySpec && (!QuantityKindSpec) +inline constexpr bool is_quantity_spec_with_no_specifiers = true; + +} // namespace detail } // namespace mp_units