Fix macros for overloaded comparisons

This commit is contained in:
Scott Lahteine 2019-09-19 01:28:31 -05:00
parent 86e0b9eb05
commit 1803c27afb

View File

@ -103,14 +103,14 @@
// C++11 solution that is standards compliant.
template <class V, class N> static inline constexpr void NOLESS(V& v, const N n) {
if (v < n) v = n;
if (n > v) v = n;
}
template <class V, class N> static inline constexpr void NOMORE(V& v, const N n) {
if (v > n) v = n;
if (n < v) v = n;
}
template <class V, class N1, class N2> static inline constexpr void LIMIT(V& v, const N1 n1, const N2 n2) {
if (v < n1) v = n1;
else if (v > n2) v = n2;
if (n1 > v) v = n1;
else if (n2 < v) v = n2;
}
#else
@ -120,21 +120,21 @@
#define NOLESS(v, n) \
do{ \
__typeof__(n) _n = (n); \
if (v < _n) v = _n; \
if (_n > v) v = _n; \
}while(0)
#define NOMORE(v, n) \
do{ \
__typeof__(n) _n = (n); \
if (v > _n) v = _n; \
if (_n < v) v = _n; \
}while(0)
#define LIMIT(v, n1, n2) \
do{ \
__typeof__(n1) _n1 = (n1); \
__typeof__(n2) _n2 = (n2); \
if (v < _n1) v = _n1; \
else if (v > _n2) v = _n2; \
if (_n1 > v) v = _n1; \
else if (_n2 < v) v = _n2; \
}while(0)
#endif