diff --git a/src/core/include/units/base_dimension.h b/src/core/include/units/base_dimension.h index 14421e25..7515d97b 100644 --- a/src/core/include/units/base_dimension.h +++ b/src/core/include/units/base_dimension.h @@ -50,8 +50,7 @@ namespace units { * @tparam Symbol an unique identifier of the base dimension used to provide dimensional analysis support * @tparam U a base unit to be used for this base dimension */ -template - requires U::is_named +template struct base_dimension { static constexpr auto symbol = Symbol; ///< Unique base dimension identifier using base_unit = U; ///< Base unit adopted for this dimension diff --git a/src/core/include/units/bits/basic_concepts.h b/src/core/include/units/bits/basic_concepts.h index ecff7a2f..617fec05 100644 --- a/src/core/include/units/bits/basic_concepts.h +++ b/src/core/include/units/bits/basic_concepts.h @@ -96,9 +96,18 @@ void to_base_scaled_unit(const volatile scaled_unit*); template concept Unit = requires(T* t) { detail::to_base_scaled_unit(t); }; +namespace detail { + +template +inline constexpr bool is_named = false; + +} + +template +concept NamedUnit = Unit && detail::is_named; + // BaseDimension -template - requires U::is_named +template struct base_dimension; namespace detail { diff --git a/src/core/include/units/bits/unit_text.h b/src/core/include/units/bits/unit_text.h index ec6675bc..917c7f86 100644 --- a/src/core/include/units/bits/unit_text.h +++ b/src/core/include/units/bits/unit_text.h @@ -110,7 +110,7 @@ template constexpr auto exponent_list_with_named_units(Exp) { using dim = TYPENAME Exp::dimension; - if constexpr (dimension_unit::is_named) { + if constexpr (NamedUnit>) { return exponent_list(); } else { using recipe = TYPENAME dim::recipe; diff --git a/src/core/include/units/unit.h b/src/core/include/units/unit.h index f2faf55d..483826b4 100644 --- a/src/core/include/units/unit.h +++ b/src/core/include/units/unit.h @@ -79,7 +79,6 @@ struct same_unit_reference : is_same struct named_unit : downcast_dispatch> { - static constexpr bool is_named = true; static constexpr auto symbol = Symbol; using prefix_family = PF; }; @@ -101,7 +100,6 @@ struct named_unit : downcast_dispatch> { template requires UnitRatio struct named_scaled_unit : downcast_dispatch> { - static constexpr bool is_named = true; static constexpr auto symbol = Symbol; using prefix_family = PF; }; @@ -117,10 +115,9 @@ struct named_scaled_unit : downcast_dispatch - requires U::is_named && std::same_as +template + requires std::same_as struct prefixed_unit : downcast_dispatch> { - static constexpr bool is_named = true; static constexpr auto symbol = P::symbol + U::symbol; using prefix_family = no_prefix; }; @@ -135,7 +132,6 @@ struct prefixed_unit : downcast_dispatch struct derived_unit : downcast_dispatch> { - static constexpr bool is_named = false; using prefix_family = no_prefix; }; @@ -152,11 +148,9 @@ struct derived_unit : downcast_dispatch> { * @tparam U the unit of the first composite dimension from provided derived dimension's recipe * @tparam URest the units for the rest of dimensions from the recipe */ -template - requires detail::same_scaled_units && - (U::is_named && (URest::is_named && ... && true)) +template + requires detail::same_scaled_units struct derived_deduced_unit : downcast_dispatch> { - static constexpr bool is_named = false; static constexpr auto symbol = detail::derived_symbol_text(); using prefix_family = no_prefix; }; @@ -176,7 +170,6 @@ struct derived_deduced_unit : downcast_dispatch struct alias_unit : U { - static constexpr bool is_named = true; static constexpr auto symbol = Symbol; using prefix_family = PF; }; @@ -196,10 +189,9 @@ struct alias_unit : U { // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95015 // template // requires (!AliasUnit) && std::same_as -template - requires AU::is_named && std::same_as +template + requires std::same_as struct prefixed_alias_unit : U { - static constexpr bool is_named = true; static constexpr auto symbol = P::symbol + AU::symbol; using prefix_family = no_prefix; }; @@ -211,4 +203,26 @@ struct prefixed_alias_unit : U { */ struct unknown_coherent_unit : derived_unit {}; +namespace detail { + +template +void is_named_impl(const volatile named_unit*); + +template +void is_named_impl(const volatile named_scaled_unit*); + +template +void is_named_impl(const volatile prefixed_unit*); + +template +void is_named_impl(const volatile alias_unit*); + +template +void is_named_impl(const volatile prefixed_alias_unit*); + +template +inline constexpr bool is_named = requires(U * u) { is_named_impl(u); }; + +} // namespace detail + } // namespace units