From 6fed655bc3dc6985a01ce7d96dcc7d79a62144a9 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Wed, 21 Feb 2024 10:17:04 +0100 Subject: [PATCH] refactor: `reference` interface refactored a bit to workaround clang-16 linking issues --- src/core/include/mp-units/reference.h | 78 +++++++-------------------- 1 file changed, 20 insertions(+), 58 deletions(-) diff --git a/src/core/include/mp-units/reference.h b/src/core/include/mp-units/reference.h index 505cd08bb..589d9bb6f 100644 --- a/src/core/include/mp-units/reference.h +++ b/src/core/include/mp-units/reference.h @@ -30,6 +30,13 @@ namespace mp_units { +namespace detail { + +template +using reference_t = reference, std::remove_const_t>; + +} + [[nodiscard]] consteval QuantitySpec auto get_quantity_spec(AssociatedUnit auto u) { return detail::get_associated_quantity(u); @@ -68,75 +75,42 @@ struct reference { } template - [[nodiscard]] friend consteval reference, - std::remove_const_t> - operator*(reference, reference) + [[nodiscard]] friend consteval detail::reference_t operator*(reference, reference) { return {}; } template -#if MP_UNITS_COMP_MSVC - [[nodiscard]] friend consteval decltype(reference{}) operator*(reference, U2) -#else - [[nodiscard]] friend consteval reference, - std::remove_const_t> - operator*(reference, U2) -#endif + [[nodiscard]] friend consteval detail::reference_t operator*(reference, U2) { return {}; } template -#if MP_UNITS_COMP_MSVC - [[nodiscard]] friend consteval decltype(reference{}) operator*(U1, reference) -#else - [[nodiscard]] friend consteval reference, - std::remove_const_t> - operator*(U1, reference) -#endif + [[nodiscard]] friend consteval detail::reference_t operator*(U1, reference) { return {}; } template - [[nodiscard]] friend consteval reference, - std::remove_const_t> - operator/(reference, reference) + [[nodiscard]] friend consteval detail::reference_t operator/(reference, reference) { return {}; } template -#if MP_UNITS_COMP_MSVC - [[nodiscard]] friend consteval decltype(reference{}) operator/(reference, U2) -#else - [[nodiscard]] friend consteval reference, - std::remove_const_t> - operator/(reference, U2) -#endif + [[nodiscard]] friend consteval detail::reference_t operator/(reference, U2) { return {}; } template -#if MP_UNITS_COMP_MSVC - [[nodiscard]] friend consteval decltype(reference{}) operator/(U1, reference) -#else - [[nodiscard]] friend consteval reference, - std::remove_const_t> - operator/(U1, reference) -#endif + [[nodiscard]] friend consteval detail::reference_t operator/(U1, reference) { return {}; } - [[nodiscard]] friend consteval reference, - std::remove_const_t> - inverse(reference) - { - return {}; - } + [[nodiscard]] friend consteval detail::reference_t inverse(reference) { return {}; } /** * @brief Computes the value of a reference raised to the `Num/Den` power @@ -149,9 +123,7 @@ struct reference { */ template requires detail::non_zero - [[nodiscard]] friend consteval reference(Q{}))>, - std::remove_const_t(U{}))>> - pow(reference) + [[nodiscard]] friend consteval detail::reference_t(Q{}), pow(U{})> pow(reference) { return {}; } @@ -163,12 +135,7 @@ struct reference { * * @return The result of computation */ - [[nodiscard]] friend consteval reference, - std::remove_const_t> - sqrt(reference) - { - return {}; - } + [[nodiscard]] friend consteval detail::reference_t sqrt(reference) { return {}; } /** * @brief Computes the cubic root of a reference @@ -177,12 +144,7 @@ struct reference { * * @return The result of computation */ - [[nodiscard]] friend consteval reference, - std::remove_const_t> - cbrt(reference) - { - return {}; - } + [[nodiscard]] friend consteval detail::reference_t cbrt(reference) { return {}; } template [[nodiscard]] friend consteval bool convertible(reference, reference) @@ -275,9 +237,9 @@ template } -> Unit; } { - return reference, - std::remove_const_t>{}; + return detail::reference_t{}; } namespace detail {