diff options
author | Nat Goodspeed <nat@lindenlab.com> | 2023-03-01 14:33:35 -0500 |
---|---|---|
committer | Nat Goodspeed <nat@lindenlab.com> | 2023-03-01 14:33:35 -0500 |
commit | 18ac7ab027217e05876a066c86ab3fbaa2a7328f (patch) | |
tree | 7bffff7cef1a357f4fea4761d417e8d417026597 /indra | |
parent | 1bba8fd31e2dabf27fe2b4b9177bf156799d7299 (diff) |
SL-18330: Use recursive variadic llmax(), llmin()
instead of having specific binary, ternary and quaternary overloads.
Diffstat (limited to 'indra')
-rw-r--r-- | indra/llcommon/lldefs.h | 48 |
1 files changed, 17 insertions, 31 deletions
diff --git a/indra/llcommon/lldefs.h b/indra/llcommon/lldefs.h index 5c46f6a796..4e25001fff 100644 --- a/indra/llcommon/lldefs.h +++ b/indra/llcommon/lldefs.h @@ -167,48 +167,34 @@ const U32 MAXADDRSTR = 17; // 123.567.901.345 = 15 chars + \0 + 1 for good luc // // defined for U16, U32, U64, S16, S32, S64, : // llclampb(a) // clamps a to [0 .. 255] -// - -template <typename T1, typename T2> -inline auto llmax(T1 d1, T2 d2) -{ - return (d1 > d2) ? d1 : d2; -} - -template <typename T1, typename T2, typename T3> -inline auto llmax(T1 d1, T2 d2, T3 d3) -{ - auto r = llmax(d1,d2); - return llmax(r, d3); -} +// -template <typename T1, typename T2, typename T3, typename T4> -inline auto llmax(T1 d1, T2 d2, T3 d3, T4 d4) +// recursion tail +template <typename T> +inline auto llmax(T data) { - auto r1 = llmax(d1,d2); - auto r2 = llmax(d3,d4); - return llmax(r1, r2); + return data; } -template <typename T1, typename T2> -inline auto llmin(T1 d1, T2 d2) +template <typename T0, typename T1, typename... Ts> +inline auto llmax(T0 d0, T1 d1, Ts... rest) { - return (d1 < d2) ? d1 : d2; + auto maxrest = llmax(d1, rest...); + return (d0 > maxrest)? d0 : maxrest; } -template <typename T1, typename T2, typename T3> -inline auto llmin(T1 d1, T2 d2, T3 d3) +// recursion tail +template <typename T> +inline auto llmin(T data) { - auto r = llmin(d1,d2); - return (r < d3 ? r : d3); + return data; } -template <typename T1, typename T2, typename T3, typename T4> -inline auto llmin(T1 d1, T2 d2, T3 d3, T4 d4) +template <typename T0, typename T1, typename... Ts> +inline auto llmin(T0 d0, T1 d1, Ts... rest) { - auto r1 = llmin(d1,d2); - auto r2 = llmin(d3,d4); - return llmin(r1, r2); + auto minrest = llmin(d1, rest...); + return (d0 < minrest) ? d0 : minrest; } template <typename A, typename MIN, typename MAX> |