浏览代码

add LIMIT

ithewei 6 年之前
父节点
当前提交
85ac09c357
共有 1 个文件被更改,包括 4 次插入0 次删除
  1. 4 0
      hdef.h

+ 4 - 0
hdef.h

@@ -107,6 +107,10 @@ typedef std::map<std::string, std::string> keyval_t;
 #define MIN(a, b) ((a) < (b) ? (a) : (b))
 #endif
 
+#ifndef LIMIT
+#define LIMIT(lower, v, upper) MIN(MAX((lower), (v)), (upper))
+#endif
+
 #ifndef ARRAY_SIZE
 #define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0]))
 #endif