#define IF_ELSE(a) CAT2(_IF_, BOOL(a)) #define _IF_0(...) _ELSE_0 #define _IF_1(...) __VA_ARGS__ _ELSE_1 #define _ELSE_0(...) __VA_ARGS__ #define _ELSE_1(...) #define _NOT_0 amogus, 1 #define BOOL(a) NOT(NOT(a)) #define FIRST(a, ...) a #define SECOND(a, b, ...) b #define _CHECK(...) SECOND(__VA_ARGS__, 0) #define NOT(a) _CHECK(CAT(_NOT_, a)) #define CAT(a, b) a ## b #define CAT2(a, b) CAT(a, b) /* IF_ELSE(0)(amogus)(N) IF_ELSE(1)(amogus)(sugoma) IF_ELSE(2)(amogus)(sugoma) */ #define _FOR() FOR #define FOR(macr, a, ...) macr(a) IF_ELSE(HAS_ARGS(__VA_ARGS__)) (PUSH2(_FOR)()(macr, __VA_ARGS__)) () #define AMOGUS(a) sugoma a // FOR(AMOGUS, amogus, sugoma, 1) #define SCAN1(a) a #define SCAN2(a) SCAN1(SCAN1(a)) #define SCAN4(a) SCAN2(SCAN2(a)) #define SCAN8(a) SCAN4(SCAN4(a)) #define SCAN16(a) SCAN8(SCAN8(a)) #define NONE() #define HAS_ARGS(...) BOOL(FIRST(_NO_ARGS __VA_ARGS__)()) #define _NO_ARGS() 0 #define _REC() REC #define PUSH(macr) macr NONE() #define PUSH2(macr) macr NONE NONE()() #define REC(a) sugoma PUSH(_REC)()(a) #define AND(a, b) CAT(_AND_, CAT(a, b)) #define _AND_00 0 #define _AND_10 0 #define _AND_01 0 #define _AND_11 1 #define GEN_FUNC(type) type sum(type a, type b) { return a + b; } // SCAN8(FOR(AMOGUS, 123, 123, 321)) #include SCAN16(FOR(GEN_FUNC, double, int, float)) int main() { std::cout << sum(0., 1.) << "\n"; std::cout << sum(0, 1) << "\n"; std::cout << sum((float)0, 1.) << "\n"; }