diff --git a/src/core/include/mp-units/bits/get_associated_quantity.h b/src/core/include/mp-units/bits/get_associated_quantity.h index 881c61e8..10640ea9 100644 --- a/src/core/include/mp-units/bits/get_associated_quantity.h +++ b/src/core/include/mp-units/bits/get_associated_quantity.h @@ -34,24 +34,25 @@ template template [[nodiscard]] consteval auto all_are_kinds(power) { - return all_are_kinds(U{}); + return decltype(all_are_kinds(U{})){}; } template -[[nodiscard]] consteval bool all_are_kinds(type_list, type_list) +[[nodiscard]] consteval auto all_are_kinds(type_list, type_list) { - return (... && all_are_kinds(Nums{})) && (... && all_are_kinds(Dens{})); + return std::bool_constant<((... && decltype(all_are_kinds(Nums{}))::value) && + (... && decltype(all_are_kinds(Dens{}))::value))>{}; } template [[nodiscard]] consteval auto all_are_kinds(U) { if constexpr (requires { U::quantity_spec; }) - return QuantityKindSpec>; + return std::bool_constant>>{}; else if constexpr (requires { U::reference_unit; }) - return all_are_kinds(U::reference_unit); + return decltype(all_are_kinds(U::reference_unit)){}; else if constexpr (requires { typename U::_num_; }) { - return all_are_kinds(typename U::_num_{}, typename U::_den_{}); + return decltype(all_are_kinds(typename U::_num_{}, typename U::_den_{})){}; } } @@ -67,20 +68,21 @@ template if constexpr (requires { U::quantity_spec; }) return remove_kind(U::quantity_spec); else if constexpr (requires { U::reference_unit; }) - return get_associated_quantity_impl(U::reference_unit); + return decltype(get_associated_quantity_impl(U::reference_unit)){}; else if constexpr (requires { typename U::_num_; }) { - return expr_map(u); + return decltype(expr_map(u)){}; } } template [[nodiscard]] consteval auto get_associated_quantity(U u) { - constexpr bool all_kinds = all_are_kinds(u); + constexpr bool all_kinds = decltype(all_are_kinds(u)){}; if constexpr (all_kinds) - return kind_of; + return kind_of; else - return get_associated_quantity_impl(u); + return decltype(get_associated_quantity_impl(u)){}; } } // namespace mp_units::detail diff --git a/src/core/include/mp-units/bits/quantity_spec_hierarchy.h b/src/core/include/mp-units/bits/quantity_spec_hierarchy.h index 1346fa89..5a3c0b70 100644 --- a/src/core/include/mp-units/bits/quantity_spec_hierarchy.h +++ b/src/core/include/mp-units/bits/quantity_spec_hierarchy.h @@ -26,12 +26,12 @@ namespace mp_units::detail { -[[nodiscard]] consteval std::size_t hierarchy_path_length(QuantitySpec auto q) +[[nodiscard]] consteval auto hierarchy_path_length(QuantitySpec auto q) { if constexpr (requires { q._parent_; }) - return hierarchy_path_length(q._parent_) + 1; + return std::integral_constant{}; else - return 1; + return std::integral_constant{}; } template @@ -41,51 +41,53 @@ template if constexpr (Offset == 0) return q; else if constexpr (requires { q._parent_; }) - return hierarchy_path_advance(q._parent_); + return decltype(hierarchy_path_advance(q._parent_)){}; } template -[[nodiscard]] consteval bool have_common_base_in_hierarchy_of_equal_length(A a, B b) +[[nodiscard]] consteval auto have_common_base_in_hierarchy_of_equal_length(A a, B b) { if constexpr (is_same_v) - return true; + return std::true_type{}; else if constexpr (requires { a._parent_; }) - return have_common_base_in_hierarchy_of_equal_length(a._parent_, b._parent_); + return decltype(have_common_base_in_hierarchy_of_equal_length(a._parent_, b._parent_)){}; else - return false; + return std::false_type{}; } template [[nodiscard]] consteval auto have_common_base(A a, B b) { - constexpr std::size_t a_length = hierarchy_path_length(A{}); - constexpr std::size_t b_length = hierarchy_path_length(B{}); + constexpr std::size_t a_length = decltype(hierarchy_path_length(A{}))::value; + constexpr std::size_t b_length = decltype(hierarchy_path_length(B{}))::value; if constexpr (a_length > b_length) - return have_common_base_in_hierarchy_of_equal_length(hierarchy_path_advance(a), b); + return decltype(have_common_base_in_hierarchy_of_equal_length( + decltype(hierarchy_path_advance(a)){}, b)){}; else - return have_common_base_in_hierarchy_of_equal_length(a, hierarchy_path_advance(b)); + return decltype(have_common_base_in_hierarchy_of_equal_length( + a, decltype(hierarchy_path_advance(b)){})){}; } template - requires(have_common_base_in_hierarchy_of_equal_length(A{}, B{})) -[[nodiscard]] consteval auto get_common_base_for_hierarchy_of_equal_length(A a, B b) + requires(decltype(have_common_base_in_hierarchy_of_equal_length(A{}, B{}))::value) +[[nodiscard]] consteval QuantitySpec auto get_common_base_for_hierarchy_of_equal_length(A a, B b) { if constexpr (is_same_v) return a; else - return get_common_base_for_hierarchy_of_equal_length(a._parent_, b._parent_); + return decltype(get_common_base_for_hierarchy_of_equal_length(a._parent_, b._parent_)){}; } template - requires(have_common_base(A{}, B{})) -[[nodiscard]] consteval auto get_common_base(A a, B b) + requires(decltype(have_common_base(A{}, B{}))::value) +[[nodiscard]] consteval QuantitySpec auto get_common_base(A a, B b) { - constexpr int a_length = hierarchy_path_length(A{}); - constexpr int b_length = hierarchy_path_length(B{}); + constexpr std::size_t a_length = decltype(hierarchy_path_length(A{}))::value; + constexpr std::size_t b_length = decltype(hierarchy_path_length(B{}))::value; if constexpr (a_length > b_length) - return get_common_base_for_hierarchy_of_equal_length(hierarchy_path_advance(a), b); + return decltype(get_common_base_for_hierarchy_of_equal_length(hierarchy_path_advance(a), b)){}; else - return get_common_base_for_hierarchy_of_equal_length(a, hierarchy_path_advance(b)); + return decltype(get_common_base_for_hierarchy_of_equal_length(a, hierarchy_path_advance(b))){}; } template @@ -94,8 +96,8 @@ template if constexpr (Child{} == Parent{}) return std::true_type{}; else { - constexpr auto child_length = hierarchy_path_length(Child{}); - constexpr auto parent_length = hierarchy_path_length(Parent{}); + constexpr std::size_t child_length = decltype(hierarchy_path_length(Child{}))::value; + constexpr std::size_t parent_length = decltype(hierarchy_path_length(Parent{}))::value; if constexpr (parent_length > child_length) return std::false_type{}; else diff --git a/src/core/include/mp-units/framework/reference.h b/src/core/include/mp-units/framework/reference.h index 746abb44..345c2384 100644 --- a/src/core/include/mp-units/framework/reference.h +++ b/src/core/include/mp-units/framework/reference.h @@ -46,7 +46,7 @@ MP_UNITS_EXPORT_BEGIN [[nodiscard]] consteval QuantitySpec auto get_quantity_spec(AssociatedUnit auto u) { - return detail::get_associated_quantity(u); + return decltype(detail::get_associated_quantity(u)){}; } /**