Guest User

Untitled

a guest
Jan 17th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.20 KB | None | 0 0
  1. #include <cstddef>
  2. #include <utility>
  3.  
  4. namespace umeta {
  5. template<typename T>
  6. struct type_check;
  7.  
  8. template<typename ... TL>
  9. struct list {};
  10.  
  11. template<typename T>
  12. struct identity;
  13.  
  14. template<typename T>
  15. struct identity {
  16. using type = T;
  17. };
  18.  
  19. template<std::size_t I, typename ... TL>
  20. struct at;
  21.  
  22. template<typename T, typename ... TL>
  23. struct at<0, T, TL...> : identity<T> {};
  24.  
  25. template<std::size_t I, typename T, typename ... TL>
  26. struct at<I, T, TL...> : at<I - 1, TL...> {};
  27.  
  28. template<typename ... TL>
  29. struct at_front;
  30.  
  31. template<typename ... TL>
  32. struct at_front : identity<at<0, TL...>> {};
  33.  
  34. template<typename ... TL>
  35. struct at_back;
  36.  
  37. template<typename ... TL>
  38. struct at_back : identity<typename at<sizeof...(TL) - 1, TL...>::type> {};
  39.  
  40. template<
  41. template <bool, bool> class Joiner,
  42. template <typename, typename> class Test,
  43. typename L1,
  44. typename L2>
  45. class check_pairs;
  46.  
  47. template<
  48. template <bool, bool> class Joiner,
  49. template <typename, typename> class Test,
  50. typename L1,
  51. typename L2>
  52. class check_pairs {
  53. template<
  54. typename T1, typename... TL1,
  55. typename T2, typename... TL2>
  56. static constexpr bool checker(list<T1, TL1...> const&, list<T2, TL2...> const&) {
  57. return Joiner<Test<T1, T2>::value, checker(list<TL1...>{}, list<TL2...>{})>::value;
  58. }
  59.  
  60. template<
  61. typename T1,
  62. typename T2>
  63. static constexpr bool checker(list<T1> const&, list<T2> const&) {
  64. return Test<T1, T2>::value;
  65. }
  66. public:
  67. static constexpr bool value = checker(L1{}, L2{});
  68. };
  69.  
  70. template<
  71. template <bool, bool> class Joiner,
  72. template <typename> class Test,
  73. typename L>
  74. struct check;
  75.  
  76. template<
  77. template <bool, bool> class Joiner,
  78. template <typename> class Test,
  79. typename L>
  80. struct check {
  81. template<typename T, typename... TL>
  82. static constexpr bool checker(list<T, TL...> const&) {
  83. return Joiner<Test<T>::value, checker(list<TL...>{})>::value;
  84. }
  85.  
  86. template<typename T>
  87. static constexpr bool checker(list<T> const&) {
  88. return Test<T>::value;
  89. }
  90. public:
  91. static constexpr bool value = checker(L{});
  92. };
  93.  
  94. template<bool B1, bool B2>
  95. struct logic_and : std::bool_constant<B1 && B2> {};
  96.  
  97. template<bool B1, bool B2>
  98. struct logic_or : std::bool_constant<B1 || B2> {};
  99.  
  100. template<bool B1, bool B2>
  101. struct logic_xor : std::bool_constant<B1 ^ B2> {};
  102.  
  103. template<
  104. template <typename, typename> class Test,
  105. typename L1,
  106. typename L2>
  107. using check_pairs_all = check_pairs<logic_and, Test, L1, L2>;
  108.  
  109. template<
  110. template <typename, typename> class Test,
  111. typename L1,
  112. typename L2>
  113. using check_pairs_any = check_pairs<logic_or, Test, L1, L2>;
  114.  
  115. template<
  116. template <typename> class Test,
  117. typename L>
  118. using check_all = check<logic_and, Test, L>;
  119.  
  120. template<
  121. template <typename> class Test,
  122. typename L>
  123. using check_any = check<logic_or, Test, L>;
  124. }
Add Comment
Please, Sign In to add comment