Guest User

Untitled

a guest
Aug 21st, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. #define NOTHING
  2. #define DEFD(a) ((0 == a)?(NOTHING):(1))
  3.  
  4. #define PRIMITIVE_CAT(a, ...) a ## __VA_ARGS__
  5.  
  6. #define COMPL(b) PRIMITIVE_CAT(COMPL_, b)
  7. #define COMPL_0 1
  8. #define COMPL_1 0
  9.  
  10.  
  11. #define CHECK_N(x, n, ...) n
  12. #define CHECK(...) CHECK_N(__VA_ARGS__, 0,)
  13. #define PROBE(x) x, 1,
  14.  
  15. #define IS_PAREN(x) CHECK(IS_PAREN_PROBE x)
  16. #define IS_PAREN_PROBE(...) PROBE(~)
  17.  
  18. #define NOT(x) CHECK(PRIMITIVE_CAT(NOT_, x))
  19. #define NOT_0 PROBE(~)
  20.  
  21. #define BOOL(x) COMPL(NOT(x))
  22.  
  23. #define IIF(c) PRIMITIVE_CAT(IIF_, c)
  24. #define IIF_0(t, ...) __VA_ARGS__
  25. #define IIF_1(t, ...) t
  26.  
  27. #define IF(c) IIF(BOOL(c))
  28.  
  29. #define EAT(...)
  30. #define EXPAND(...) __VA_ARGS__
  31. #define WHEN(c) IF(c)(EXPAND, EAT)
  32.  
  33. #define SQUARE(b,a) (WHEN(a)((b)*(b)))
  34.  
  35. printf("---%d",SQUARE(2));
  36.  
  37. printf("---%d",SQUARE(0));
Add Comment
Please, Sign In to add comment