Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. #define C_MAX_2(a, b) (((a) > (b)) ? (a) : (b))
  2. #define C_MAX_3(a, b, c) C_MAX_2((C_MAX_2((a),(b))), (c))
  3. #define C_MAX_4(a, b, c, d) C_MAX_2((C_MAX_2((a),(b))),
  4. (C_MAX_2((c),(d))))
  5. #define C_MAX_5(a, b, c, d, e) C_MAX_2((C_MAX_3((a),(b), (c))),
  6. (C_MAX_2((d),(e))))
  7.  
  8. #define MAX_2(n1, n2) (n1 > n2 ? n1 : n2)
  9. #define MAX_3(n1, n2, n3) MAX_2(n1, MAX_2(n2, n3))
  10. #define MAX_4(n1, n2, n3, n4) MAX_2(n1, MAX_3(n2, n3, n4))
  11. #define MAX_5(n1, n2, n3, n4, n5) MAX_2(n1, MAX_4(n2, n3, n4, n5))
  12.  
  13. #define COUNTARGS(...) GET21ST(__VA_ARGS__,COUNTDOWN())
  14. #define COUNTDOWN() 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
  15. #define GET21ST(a20,a19,a18,a17,a16,a15,a14,a13,a12,a11,a10,a9,a8,a7,a6,a5,a4,a3,a2,a1,a,...) a
  16.  
  17. #define EVAL(...) EVAL1(EVAL1(EVAL1(__VA_ARGS__)))
  18. #define EVAL1(...) EVAL2(EVAL2(EVAL2(__VA_ARGS__)))
  19. #define EVAL2(...) EVAL3(EVAL3(EVAL3(__VA_ARGS__)))
  20. #define EVAL3(...) EVAL4(EVAL4(EVAL4(__VA_ARGS__)))
  21. #define EVAL4(...) EVAL5(EVAL5(EVAL5(__VA_ARGS__)))
  22. #define EVAL5(...) __VA_ARGS__
  23.  
  24. #define VANISH()
  25. #define OBSTRUCT(...) __VA_ARGS__ VANISH()
  26. #define COUNTDOWN() 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
  27. #define COUNTARGS(...) EVAL(OBSTRUCT(GET21ST)(__VA_ARGS__,COUNTDOWN()))
  28. #define GET21ST(a20,a19,a18,a17,a16,a15,a14,a13,a12,a11,a10,a9,a8,a7,a6,a5,a4,a3,a2,a1,a,...) a
  29.  
  30. #define MAX_1(n) n
  31. #define MAX_2(a,b) ((a)>(b)?(a):(b))
  32. #define MAX_3(a,...) MAX_2(a,MAX_2(__VA_ARGS__))
  33. #define MAX_4(a,...) MAX_2(a,MAX_3(__VA_ARGS__))
  34. ...
  35. #define MAX_20(a,...) MAX_2(a,MAX_19(__VA_ARGS__))
  36.  
  37. #define CAT(a, ...) PRIMITIVE_CAT(a, __VA_ARGS__)
  38. #define PRIMITIVE_CAT(a, ...) a ## __VA_ARGS__
  39.  
  40. #define MAX(...) CAT(MAX_,COUNTARGS(__VA_ARGS__))(__VA_ARGS__)
  41.  
  42. MAX(2,3,4,1)
  43.  
  44. (2>(3>(4>1?4:1)?3:(4>1?4:1))?2:(3>(4>1?4:1)?3:(4>1?4:1)))
  45.  
  46. #include <vector>
  47. #include <algorithm>
  48.  
  49. #define MAX(...) [](auto v)constexpr{
  50. return *std::max_element(v.begin(),
  51. v.end());
  52. }(std::vector<float>{__VA_ARGS__})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement