From 045410707e46f704fa3e3e7e431fe551b71b93fe Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Sun, 27 Oct 2024 08:02:03 +0100 Subject: [PATCH] refactor: `expr_fractions` takes direct `OneType` type now instead of a trait --- src/core/include/mp-units/framework/dimension.h | 12 +----------- .../mp-units/framework/expression_template.h | 6 +++--- .../include/mp-units/framework/quantity_spec.h | 14 ++------------ src/core/include/mp-units/framework/unit.h | 8 +------- 4 files changed, 7 insertions(+), 33 deletions(-) diff --git a/src/core/include/mp-units/framework/dimension.h b/src/core/include/mp-units/framework/dimension.h index 24a1e7b8..2b8d3887 100644 --- a/src/core/include/mp-units/framework/dimension.h +++ b/src/core/include/mp-units/framework/dimension.h @@ -59,9 +59,6 @@ MP_UNITS_EXPORT struct dimension_one; namespace detail { -template -struct is_dimension_one : std::false_type {}; - template struct base_dimension_less : std::bool_constant() < type_name()> {}; @@ -69,7 +66,7 @@ template using type_list_of_base_dimension_less = expr_less; template -struct derived_dimension_impl : expr_fractions {}; +struct derived_dimension_impl : expr_fractions {}; struct dimension_interface { template @@ -183,13 +180,6 @@ MP_UNITS_EXPORT inline constexpr struct dimension_one final : detail::derived_dimension_impl<> { } dimension_one; -namespace detail { - -template<> -struct is_dimension_one : std::true_type {}; - -} // namespace detail - MP_UNITS_EXPORT_BEGIN [[nodiscard]] consteval Dimension auto inverse(Dimension auto d) { return dimension_one / d; } diff --git a/src/core/include/mp-units/framework/expression_template.h b/src/core/include/mp-units/framework/expression_template.h index 9b7e2a6c..17e40512 100644 --- a/src/core/include/mp-units/framework/expression_template.h +++ b/src/core/include/mp-units/framework/expression_template.h @@ -294,7 +294,7 @@ struct expr_fractions_result { using _den_ = Den; // exposition only }; -template typename OneType, typename List> +template [[nodiscard]] consteval auto expr_fractions_impl() { constexpr std::size_t size = type_list_size; @@ -307,7 +307,7 @@ template typename OneType, typename List> using last_element = type_list_back; if constexpr (is_specialization_of) { - if constexpr (size == 2 && OneType>::value) + if constexpr (size == 2 && is_same_v, OneType>) return expr_fractions_result, type_list_map>{}; else { using split = type_list_split; @@ -322,7 +322,7 @@ template typename OneType, typename List> /** * @brief Divides expression template spec to numerator and denominator parts */ -template typename OneType, typename... Ts> +template struct expr_fractions : decltype(expr_fractions_impl>()) {}; // expr_make_spec diff --git a/src/core/include/mp-units/framework/quantity_spec.h b/src/core/include/mp-units/framework/quantity_spec.h index e2fbefc0..3f4eb4d2 100644 --- a/src/core/include/mp-units/framework/quantity_spec.h +++ b/src/core/include/mp-units/framework/quantity_spec.h @@ -429,9 +429,6 @@ struct quantity_spec : detail::quantity_spec_interface -struct is_dimensionless : std::false_type {}; - template struct derived_quantity_spec_impl : #if MP_UNITS_API_NO_CRTP @@ -439,9 +436,9 @@ struct derived_quantity_spec_impl : #else detail::quantity_spec_interface>, #endif - detail::expr_fractions { + detail::expr_fractions { using _base_type_ = derived_quantity_spec_impl; - using _base_ = detail::expr_fractions; + using _base_ = detail::expr_fractions; static constexpr Dimension auto dimension = detail::expr_map */ MP_UNITS_EXPORT QUANTITY_SPEC(dimensionless, derived_quantity_spec<>{}); -namespace detail { - -template<> -struct is_dimensionless : std::true_type {}; - -} // namespace detail - /** * @brief Quantity kind specifier * diff --git a/src/core/include/mp-units/framework/unit.h b/src/core/include/mp-units/framework/unit.h index 5d6f6e2b..b7f2aa06 100644 --- a/src/core/include/mp-units/framework/unit.h +++ b/src/core/include/mp-units/framework/unit.h @@ -461,11 +461,8 @@ struct common_unit final : decltype(detail::get_common_scaled_unit(U1{}, U2{}, R namespace detail { -template -struct is_one : std::false_type {}; - template -struct derived_unit_impl : detail::unit_interface, detail::expr_fractions { +struct derived_unit_impl : detail::unit_interface, detail::expr_fractions { using _base_type_ = derived_unit_impl; // exposition only }; @@ -530,9 +527,6 @@ MP_UNITS_EXPORT inline constexpr struct one final : detail::derived_unit_impl<> namespace detail { -template<> -struct is_one : std::true_type {}; - template [[nodiscard]] consteval auto get_canonical_unit_impl(T, const scaled_unit_impl&) {