[ create a new paste ] login | about

Link: http://codepad.org/cn07cWah    [ raw code | output | fork ]

DigitalGhost - C++, pasted on Sep 3:
#include <iostream>

#define PP_IF(c, t, f) PP_IF_I(c, t, f)
#define PP_IF_I(c, t, f) PP_IF_ ## c(t, f)
#define PP_IF_0(t, f) f
#define PP_IF_1(t, f) t

#define PP_APPLY PP_LOOKUP_UNEXPANDED_APPLY_1()

#define PP_LOOKUP_UNEXPANDED_APPLY_1() PP_IF(PP_CAT(PP_CHECK_APPLY_, PP_APPLY_1(PP_CHECK_APPLY_F, PP_NIL)), PP_APPLY_1, PP_LOOKUP_UNEXPANDED_APPLY_2())
#define PP_LOOKUP_UNEXPANDED_APPLY_2() PP_IF(PP_CAT(PP_CHECK_APPLY_, PP_APPLY_2(PP_CHECK_APPLY_F, PP_NIL)), PP_APPLY_2, PP_LOOKUP_UNEXPANDED_APPLY_3())
#define PP_LOOKUP_UNEXPANDED_APPLY_3() PP_IF(PP_CAT(PP_CHECK_APPLY_, PP_APPLY_3(PP_CHECK_APPLY_F, PP_NIL)), PP_APPLY_3, PP_LOOKUP_UNEXPANDED_APPLY_4())
#define PP_LOOKUP_UNEXPANDED_APPLY_4() PP_IF(PP_CAT(PP_CHECK_APPLY_, PP_APPLY_4(PP_CHECK_APPLY_F, PP_NIL)), PP_APPLY_4, PP_LOOKUP_ERROR)

#define PP_CHECK_APPLY_F(_) PP_UNEXPANDED_APPLY

#define PP_CHECK_APPLY_PP_UNEXPANDED_APPLY 1
#define PP_CHECK_APPLY_PP_APPLY_1(f, x) 0
#define PP_CHECK_APPLY_PP_APPLY_2(f, x) 0
#define PP_CHECK_APPLY_PP_APPLY_3(f, x) 0
#define PP_CHECK_APPLY_PP_APPLY_4(f, x) 0

#define PP_APPLY_1(f, x) f(x)
#define PP_APPLY_2(f, x) f(x)
#define PP_APPLY_3(f, x) f(x)
#define PP_APPLY_4(f, x) f(x)

#define PP_CAT(a, b) PP_CAT_I(a, b)
#define PP_CAT_I(a, b) a ## b

#define PP_TO_STR(a) PP_TO_STR_I(a)
#define PP_TO_STR_I(a) #a

#define F(x) PP_APPLY(x, x)
#define G(_) SUCCEEDED!

int main() {
  using std::cout;
  cout << PP_TO_STR(PP_APPLY(F, G)) << '\n';
}


Output:
1
SUCCEEDED!


Create a new paste based on this one


Comments: