From: Peter Munch Date: Sat, 28 Mar 2020 22:05:21 +0000 (+0100) Subject: Template Utilities::pow() X-Git-Tag: v9.2.0-rc1~335^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b9cf3f52daaa71275cd8453ee0b711aeacc59e1b;p=dealii.git Template Utilities::pow() --- diff --git a/include/deal.II/base/utilities.h b/include/deal.II/base/utilities.h index 3a16df7d51..a1db035464 100644 --- a/include/deal.II/base/utilities.h +++ b/include/deal.II/base/utilities.h @@ -480,11 +480,12 @@ namespace Utilities /** * A replacement for std::pow that allows compile-time - * calculations for constant expression arguments. The exponent @p iexp - * must not be negative. + * calculations for constant expression arguments. The @p base must + * be an integer type and the exponent @p iexp must not be negative. */ - constexpr unsigned int - pow(const unsigned int base, const int iexp) + template + constexpr T + pow(const T base, const int iexp) { #if defined(DEBUG) && defined(DEAL_II_HAVE_CXX14_CONSTEXPR) // Up to __builtin_expect this is the same code as in the 'Assert' macro. @@ -516,6 +517,8 @@ namespace Utilities // return prefactor * dealii::Utilities::pow(base*base, iexp/2); // + static_assert(std::is_integral::value, "Only integral types supported"); + return iexp <= 0 ? 1 : (((iexp % 2 == 1) ? base : 1) * dealii::Utilities::pow(base * base, iexp / 2));