From 18b16c51a0ac4e158d1e15e0e540487dcead44ee Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Wed, 12 Jun 2024 14:18:29 +0200 Subject: [PATCH] refactor: compiple-time performance optimizations for dimensions --- .../include/mp-units/framework/dimension.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/core/include/mp-units/framework/dimension.h b/src/core/include/mp-units/framework/dimension.h index 71d24719..74554a9f 100644 --- a/src/core/include/mp-units/framework/dimension.h +++ b/src/core/include/mp-units/framework/dimension.h @@ -159,15 +159,15 @@ struct is_dimension_one : std::true_type {}; MP_UNITS_EXPORT template [[nodiscard]] consteval Dimension auto operator*(Lhs, Rhs) { - return detail::expr_multiply( - Lhs{}, Rhs{}); + return decltype(detail::expr_multiply(Lhs{}, Rhs{})){}; } MP_UNITS_EXPORT template [[nodiscard]] consteval Dimension auto operator/(Lhs, Rhs) { - return detail::expr_divide(Lhs{}, - Rhs{}); + return decltype(detail::expr_divide(Lhs{}, Rhs{})){}; } namespace detail { @@ -191,7 +191,7 @@ template return is_same_v || detail::derived_from_the_same_base_dimension(lhs, rhs); } -[[nodiscard]] consteval Dimension auto inverse(Dimension auto d) { return dimension_one / d; } +[[nodiscard]] consteval Dimension auto inverse(Dimension auto d) { return decltype(dimension_one / d){}; } /** * @brief Computes the value of a dimension raised to the `Num/Den` power @@ -212,8 +212,8 @@ template else return derived_dimension>{}; } else - return detail::expr_pow(d); + return decltype(detail::expr_pow(d)){}; } /** @@ -223,7 +223,7 @@ template * * @return Dimension The result of computation */ -[[nodiscard]] consteval Dimension auto sqrt(Dimension auto d) { return pow<1, 2>(d); } +[[nodiscard]] consteval Dimension auto sqrt(Dimension auto d) { return decltype(pow<1, 2>(d)){}; } /** * @brief Computes the cubic root of a dimension @@ -232,7 +232,7 @@ template * * @return Dimension The result of computation */ -[[nodiscard]] consteval Dimension auto cbrt(Dimension auto d) { return pow<1, 3>(d); } +[[nodiscard]] consteval Dimension auto cbrt(Dimension auto d) { return decltype(pow<1, 3>(d)){}; } struct dimension_symbol_formatting {