From 991863594da9adfa9e77c5bf92fda01ca95bd97e Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Tue, 8 Sep 2020 18:37:29 +0200 Subject: [PATCH] refactor: :recycle: two pow() overloads merged into one Also fixes doxygen warnings. --- src/include/units/math.h | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/src/include/units/math.h b/src/include/units/math.h index f70ac038..b0d77117 100644 --- a/src/include/units/math.h +++ b/src/include/units/math.h @@ -39,26 +39,18 @@ namespace units { * @return Quantity The result of computation */ template - requires(N != 0) -[[nodiscard]] inline Quantity auto pow(const Q& q) noexcept +[[nodiscard]] inline auto pow(const Q& q) noexcept requires requires { std::pow(q.count(), N); } { - using dim = dimension_pow; - using unit = downcast_unit(Q::unit::ratio)>; using rep = TYPENAME Q::rep; - return quantity(static_cast(std::pow(q.count(), N))); -} - -/** - * @brief OVerload that always returns 1 for N == 0 - * - * @return Rep A scalar value of @c 1. - */ -template - requires(N == 0) -[[nodiscard]] inline TYPENAME Q::rep pow(const Q&) noexcept -{ - return 1; + if constexpr(N == 0) { + return rep(1); + } + else { + using dim = dimension_pow; + using unit = downcast_unit(Q::unit::ratio)>; + return quantity(static_cast(std::pow(q.count(), N))); + } } /**