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 @@ -97,8 +97,33 @@ void loop( void ) ;
9797#undef abs
9898#endif // abs
9999
100- #define min (a ,b ) ((a)<(b)?(a):(b))
101- #define max (a ,b ) ((a)>(b)?(a):(b))
100+ #ifdef __cplusplus
101+ template <class T , class L >
102+ auto min (const T& a, const L& b) -> decltype((b < a) ? b : a)
103+ {
104+ return (b < a) ? b : a;
105+ }
106+
107+ template <class T , class L >
108+ auto max (const T& a, const L& b) -> decltype((b < a) ? b : a)
109+ {
110+ return (a < b) ? b : a;
111+ }
112+ #else
113+ #ifndef min
114+ #define min (a,b ) \
115+ ({ __typeof__ (a) _a = (a); \
116+ __typeof__ (b) _b = (b); \
117+ _a < _b ? _a : _b; })
118+ #endif
119+ #ifndef max
120+ #define max (a,b ) \
121+ ({ __typeof__ (a) _a = (a); \
122+ __typeof__ (b) _b = (b); \
123+ _a > _b ? _a : _b; })
124+ #endif
125+ #endif
126+
102127#define abs (x ) ((x)>0 ?(x):-(x))
103128#define constrain (amt,low,high ) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
104129#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