#ifndef MISC_H #define MISC_H #ifdef GMQCC #define EVAL(...) __VA_ARGS__ #define OVERLOAD_(F, ...) F##_##__VA_COUNT__(__VA_ARGS__) #define OVERLOAD(F, ...) F##_##__VA_COUNT__(__VA_ARGS__) #else #define EMPTY() #define DEFER(id) id EMPTY() #define EVAL(...) EVAL1(EVAL1(EVAL1(__VA_ARGS__))) #define EVAL1(...) EVAL2(EVAL2(EVAL2(__VA_ARGS__))) #define EVAL2(...) EVAL3(EVAL3(EVAL3(__VA_ARGS__))) #define EVAL3(...) EVAL4(EVAL4(EVAL4(__VA_ARGS__))) #define EVAL4(...) EVAL5(EVAL5(EVAL5(__VA_ARGS__))) #define EVAL5(...) __VA_ARGS__ #define OVERLOAD___(F, _16, _15, _14, _13, _12, _11, _10, _9, _8, _7, _6, _5, _4, _3, _2, _1, n, ...) F##_##n #define OVERLOAD__(F, ...) OVERLOAD___(F,##__VA_ARGS__, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0) #define OVERLOAD_(...) DEFER(OVERLOAD__(__VA_ARGS__)) #define OVERLOAD(F, ...) OVERLOAD_(F,##__VA_ARGS__)(__VA_ARGS__) #endif #define GET(name) name##get #define GETTER(type, name) type GET(name)() { return name; } #define LAMBDA(...) { __VA_ARGS__; } // With block may not contain continue or break #define WITH(type, name, value, block) \ do \ { \ type __with_save = (name); \ name = (value); \ LAMBDA(block) \ name = __with_save; \ } \ while (0) #endif