From 7e070e1c4b01721d925a8deb7773e776eecb8840 Mon Sep 17 00:00:00 2001 From: Dmitri Naumov <dmitri.naumov@ufz.de> Date: Thu, 16 Oct 2014 17:18:47 +0200 Subject: [PATCH] [ML] A MSVC friendly alternative to MathLib::pow(). --- MathLib/MathTools.h | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/MathLib/MathTools.h b/MathLib/MathTools.h index be8b7016db7..07713af3984 100644 --- a/MathLib/MathTools.h +++ b/MathLib/MathTools.h @@ -170,11 +170,25 @@ T fastpow (T base, std::size_t exp) * Template metaprogramming, compile-time version of pow() for integral * exponents. */ +#ifdef WIN32 +template <typename T, T B, unsigned E> +struct POW +{ + static T const value = B * POW<T, B, E-1>::value; +}; + +template <typename T, T B> +struct POW<T, B, 0> +{ + static T const value = 1; +}; +#else // WIN32 template <typename T> inline constexpr T pow(T const x, unsigned const y) { - return (y == 0) ? 1 : x * pow(x, y - 1); -}; + return (y == 0) ? 1 : x * pow(x, y - 1); +} +#endif // WIN32 } // namespace -- GitLab