Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstddef>
- #include <utility>
- namespace umeta {
- template<typename T>
- struct type_check;
- template<typename ... TL>
- struct list {};
- template<typename T>
- struct identity;
- template<typename T>
- struct identity {
- using type = T;
- };
- template<std::size_t I, typename ... TL>
- struct at;
- template<typename T, typename ... TL>
- struct at<0, T, TL...> : identity<T> {};
- template<std::size_t I, typename T, typename ... TL>
- struct at<I, T, TL...> : at<I - 1, TL...> {};
- template<typename ... TL>
- struct at_front;
- template<typename ... TL>
- struct at_front : identity<at<0, TL...>> {};
- template<typename ... TL>
- struct at_back;
- template<typename ... TL>
- struct at_back : identity<typename at<sizeof...(TL) - 1, TL...>::type> {};
- template<
- template <bool, bool> class Joiner,
- template <typename, typename> class Test,
- typename L1,
- typename L2>
- class check_pairs;
- template<
- template <bool, bool> class Joiner,
- template <typename, typename> class Test,
- typename L1,
- typename L2>
- class check_pairs {
- template<
- typename T1, typename... TL1,
- typename T2, typename... TL2>
- static constexpr bool checker(list<T1, TL1...> const&, list<T2, TL2...> const&) {
- return Joiner<Test<T1, T2>::value, checker(list<TL1...>{}, list<TL2...>{})>::value;
- }
- template<
- typename T1,
- typename T2>
- static constexpr bool checker(list<T1> const&, list<T2> const&) {
- return Test<T1, T2>::value;
- }
- public:
- static constexpr bool value = checker(L1{}, L2{});
- };
- template<
- template <bool, bool> class Joiner,
- template <typename> class Test,
- typename L>
- struct check;
- template<
- template <bool, bool> class Joiner,
- template <typename> class Test,
- typename L>
- struct check {
- template<typename T, typename... TL>
- static constexpr bool checker(list<T, TL...> const&) {
- return Joiner<Test<T>::value, checker(list<TL...>{})>::value;
- }
- template<typename T>
- static constexpr bool checker(list<T> const&) {
- return Test<T>::value;
- }
- public:
- static constexpr bool value = checker(L{});
- };
- template<bool B1, bool B2>
- struct logic_and : std::bool_constant<B1 && B2> {};
- template<bool B1, bool B2>
- struct logic_or : std::bool_constant<B1 || B2> {};
- template<bool B1, bool B2>
- struct logic_xor : std::bool_constant<B1 ^ B2> {};
- template<
- template <typename, typename> class Test,
- typename L1,
- typename L2>
- using check_pairs_all = check_pairs<logic_and, Test, L1, L2>;
- template<
- template <typename, typename> class Test,
- typename L1,
- typename L2>
- using check_pairs_any = check_pairs<logic_or, Test, L1, L2>;
- template<
- template <typename> class Test,
- typename L>
- using check_all = check<logic_and, Test, L>;
- template<
- template <typename> class Test,
- typename L>
- using check_any = check<logic_or, Test, L>;
- }
Add Comment
Please, Sign In to add comment