File tree Expand file tree Collapse file tree 1 file changed +27
-2
lines changed Expand file tree Collapse file tree 1 file changed +27
-2
lines changed Original file line number Diff line number Diff line change 2828#undef abs
2929#endif // abs
3030
31- #define min (a , b ) ((a) < (b) ? (a) : (b))
32- #define max (a , b ) ((a) > (b) ? (a) : (b))
31+ #ifdef __cplusplus
32+ template <class T , class L >
33+ auto min (const T& a, const L& b) -> decltype((b < a) ? b : a)
34+ {
35+ return (b < a) ? b : a;
36+ }
37+
38+ template <class T , class L >
39+ auto max (const T& a, const L& b) -> decltype((b < a) ? b : a)
40+ {
41+ return (a < b) ? b : a;
42+ }
43+ #else
44+ #ifndef min
45+ #define min (a,b ) \
46+ ({ __typeof__ (a) _a = (a); \
47+ __typeof__ (b) _b = (b); \
48+ _a < _b ? _a : _b; })
49+ #endif
50+ #ifndef max
51+ #define max (a,b ) \
52+ ({ __typeof__ (a) _a = (a); \
53+ __typeof__ (b) _b = (b); \
54+ _a > _b ? _a : _b; })
55+ #endif
56+ #endif
57+
3358#define abs (x ) ((x) > 0 ? (x) : -(x))
3459#define constrain (amt, low, high ) ((amt) < (low) ? (low) : ((amt) > (high) ? (high) : (amt)))
3560#define round (x ) ((x) >= 0 ? (long )((x) + 0.5 ) : (long )((x)-0.5 ))
You can’t perform that action at this time.
0 commit comments