Switch between inline and constexpr for c++ version

This commit is contained in:
Paul Ferrand 2020-03-11 01:06:05 +01:00 committed by Paul Fd
parent 17c4f87d4b
commit ad44c2cea9
3 changed files with 12 additions and 4 deletions

View file

@ -17,3 +17,9 @@
#else #else
#define SFIZZ_EXPORTED_API #define SFIZZ_EXPORTED_API
#endif #endif
#if __cplusplus > 201103L
#define CONSTEXPR_OR_INLINE constexpr
#else
#define CONSTEXPR_OR_INLINE inline
#endif

View file

@ -10,6 +10,7 @@
*/ */
#pragma once #pragma once
#include "Config.h" #include "Config.h"
#include "Macros.h"
#include <algorithm> #include <algorithm>
#include <cmath> #include <cmath>
#include <random> #include <random>
@ -128,13 +129,13 @@ constexpr T clamp( T v, T lo, T hi )
} }
template<int Increment = 1, class T> template<int Increment = 1, class T>
constexpr void incrementAll(T& only) CONSTEXPR_OR_INLINE void incrementAll(T& only)
{ {
only += Increment; only += Increment;
} }
template<int Increment = 1, class T, class... Args> template<int Increment = 1, class T, class... Args>
constexpr void incrementAll(T& first, Args&... rest) CONSTEXPR_OR_INLINE void incrementAll(T& first, Args&... rest)
{ {
first += Increment; first += Increment;
incrementAll<Increment>(rest...); incrementAll<Increment>(rest...);

View file

@ -10,6 +10,7 @@
//#include <string> //#include <string>
#include <array> #include <array>
#include <cmath> #include <cmath>
#include "Macros.h"
#include "Config.h" #include "Config.h"
#include "MathHelpers.h" #include "MathHelpers.h"
@ -230,7 +231,7 @@ using modFunction = std::function<void(T&, U)>;
* @param modifier the modifier value * @param modifier the modifier value
*/ */
template<class T> template<class T>
constexpr void addToBase(T& base, T modifier) CONSTEXPR_OR_INLINE void addToBase(T& base, T modifier)
{ {
base += modifier; base += modifier;
} }
@ -241,7 +242,7 @@ constexpr void addToBase(T& base, T modifier)
* @param base * @param base
* @param modifier * @param modifier
*/ */
inline void multiplyByCents(float& base, int modifier) CONSTEXPR_OR_INLINE void multiplyByCents(float& base, int modifier)
{ {
base *= centsFactor(modifier); base *= centsFactor(modifier);
} }