--- rxvt-unicode/src/rxvtutil.h 2005/06/26 19:59:29 1.9 +++ rxvt-unicode/src/rxvtutil.h 2005/12/21 10:34:24 1.12 @@ -15,15 +15,22 @@ } byteorder; template -static inline T min (T a, U b) { return a < b ? a : (T)b; } +static inline T min (T a, U b) { return a < (T)b ? a : (T)b; } template -static inline T max (T a, U b) { return a > b ? a : (T)b; } -template -static inline void swap (T& a, T& b) { T t=a; a=b; b=t; } +static inline T max (T a, U b) { return a > (T)b ? a : (T)b; } +template +static inline T clamp (T v, U a, V b) { return v < (T)a ? a : v >(T)b ? b : v; } +template +static inline void swap (T& a, U& b) { T t=a; a=(T)b; b=(U)t; } -#define IN_RANGE(val,beg,end) \ +// in range including end +#define IN_RANGE_INC(val,beg,end) \ ((unsigned int)(val) - (unsigned int)(beg) <= (unsigned int)(end) - (unsigned int)(beg)) +// in range excluding end +#define IN_RANGE_EXC(val,beg,end) \ + ((unsigned int)(val) - (unsigned int)(beg) < (unsigned int)(end) - (unsigned int)(beg)) + struct zero_initialized { void *operator new (size_t s); void operator delete (void *p, size_t s);