From 2579a2ef480bb2f85f050d1344b503b8cd899575 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 26 Jul 2015 13:14:56 +0300 Subject: Add macro constexpr2. Depend on compiler and version it can be constexpr or empty line. This need for compilers with advanced constexpr support. --- src/localconsts.h | 6 ++++++ src/utils/mathutils.h | 16 ++++++++-------- 2 files changed, 14 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/localconsts.h b/src/localconsts.h index f54ae5659..5d73f8c53 100644 --- a/src/localconsts.h +++ b/src/localconsts.h @@ -43,6 +43,7 @@ #define final #define override #define constexpr +#define constexpr2 #define noexcept #define A_DELETE(func) #define A_DELETE_COPY(func) @@ -56,6 +57,11 @@ // #define A_DELETE_COPY #else #define ADVGCC +#if GCC_VERSION < 40900 +#define constexpr2 +#else +#define constexpr2 constexpr +#endif #endif #undef Z_NULL #define Z_NULL nullptr diff --git a/src/utils/mathutils.h b/src/utils/mathutils.h index b8dcdef9b..37de98b54 100644 --- a/src/utils/mathutils.h +++ b/src/utils/mathutils.h @@ -119,13 +119,13 @@ static constexpr const uint8_t square_roots[1000] = }; inline uint16_t getCrc16(const std::string &str) A_WARN_UNUSED; -constexpr inline float fastInvSqrt(float x) A_WARN_UNUSED; -constexpr inline float fastSqrt(const float x) A_WARN_UNUSED; +constexpr2 inline float fastInvSqrt(float x) A_WARN_UNUSED; +constexpr2 inline float fastSqrt(const float x) A_WARN_UNUSED; constexpr inline float weightedAverage(const float n1, const float n2, const float w) A_WARN_UNUSED; constexpr inline int roundDouble(const double v) A_WARN_UNUSED; -constexpr inline int powerOfTwo(const unsigned int input) A_WARN_UNUSED; -constexpr inline int fastSqrtInt(const unsigned int n) A_WARN_UNUSED; +constexpr2 inline int powerOfTwo(const unsigned int input) A_WARN_UNUSED; +constexpr2 inline int fastSqrtInt(const unsigned int n) A_WARN_UNUSED; inline uint16_t getCrc16(const std::string &str) { @@ -151,7 +151,7 @@ inline uint16_t getCrc16(const std::string &str) * Unfortunately the original creator of this function seems to be unknown. */ -constexpr inline float fastInvSqrt(float x) +constexpr2 inline float fastInvSqrt(float x) { union { int i; float x; } tmp = {0U}; const float xhalf = 0.5F * x; @@ -162,7 +162,7 @@ constexpr inline float fastInvSqrt(float x) return x; } -constexpr inline float fastSqrt(const float x) +constexpr2 inline float fastSqrt(const float x) { return 1.0F / fastInvSqrt(x); } @@ -178,7 +178,7 @@ constexpr inline int roundDouble(const double v) return (v > 0.0) ? static_cast(v + 0.5) : static_cast(v - 0.5); } -constexpr inline int powerOfTwo(const unsigned int input) +constexpr2 inline int powerOfTwo(const unsigned int input) { unsigned int value = 1; while (value < input) @@ -186,7 +186,7 @@ constexpr inline int powerOfTwo(const unsigned int input) return value; } -constexpr inline int fastSqrtInt(const unsigned int n) +constexpr2 inline int fastSqrtInt(const unsigned int n) { if (n < 1000) return static_cast(square_roots[n]); -- cgit v1.2.3-70-g09d2