From fa58958dd8549ca69cd6ab985ef4aed083e4ba51 Mon Sep 17 00:00:00 2001 From: Paul Ferrand Date: Mon, 23 Dec 2019 18:59:33 +0100 Subject: [PATCH] Variadic functions in math helpers --- src/sfizz/MathHelpers.h | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/sfizz/MathHelpers.h b/src/sfizz/MathHelpers.h index 3ca2e903..4d708a0a 100644 --- a/src/sfizz/MathHelpers.h +++ b/src/sfizz/MathHelpers.h @@ -34,12 +34,17 @@ #include #include -template -constexpr T min(T op1, T op2) { return std::min(op1, op2); } -template -constexpr T min(T op1, T op2, T op3) { return std::min(op1, std::min(op2, op3)); } -template -constexpr T min(T op1, T op2, T op3, T op4) { return std::min(op1, std::min(op2, std::min(op3, op4))); } +template +constexpr T min(T op1, T op2) +{ + return std::min(op1, op2); +} + +template +constexpr T min(T op1, Args... rest) +{ + return std::min(op1, min(rest...)); +} /** * @brief Converts db values into power (applies 10**(in/10)) @@ -131,17 +136,17 @@ constexpr T clamp( const T& v, const T& lo, const T& hi ) return (v < lo) ? lo : (hi < v) ? hi : v; } -template +template constexpr void incrementAll(T& only) { - only++; + only += Increment; } -template +template constexpr void incrementAll(T& first, Args&... rest) { - first++; - incrementAll(rest...); + first += Increment; + incrementAll(rest...); } template