Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <iostream>
- #include <type_traits>
- #include <map>
- #include <unordered_map>
- #include <set>
- #include <algorithm>
- #include <unordered_set>
- #include <vector>
- #include <deque>
- #include <forward_list>
- #include <list>
- #include <utility>
- // is_deque
- // ========
- template<typename T, typename ... Types>
- struct is_deque {
- static constexpr bool value = false;
- };
- template<typename ... Types>
- struct is_deque<std::deque<Types...>> {
- static constexpr bool value = true;
- };
- // is_forward_list
- // ===============
- template<typename T, typename ... Types>
- struct is_forward_list {
- static constexpr bool value = false;
- };
- template<typename ... Types>
- struct is_forward_list<std::forward_list<Types...>> {
- static constexpr bool value = true;
- };
- // list
- // ====
- template<typename T, typename ... Types>
- struct is_list {
- static constexpr bool value = false;
- };
- template<typename ... Types>
- struct is_list<std::list<Types...>> {
- static constexpr bool value = true;
- };
- // is_vector
- // ======
- template<typename T, typename ... Types>
- struct is_vector {
- static constexpr bool value = false;
- };
- template<typename ... Types>
- struct is_vector<std::vector<Types...>> {
- static constexpr bool value = true;
- };
- // map
- // ===
- template<typename T, typename ... Types>
- struct is_map {
- static constexpr bool value = false;
- };
- template<typename ... Types>
- struct is_map<std::map<Types...>> {
- static constexpr bool value = true;
- };
- // set
- // ===
- template<typename T, typename ... Types>
- struct is_set {
- static constexpr bool value = false;
- };
- template<typename ... Types>
- struct is_set<std::set<Types...>> {
- static constexpr bool value = true;
- };
- // unordered_map
- // =============
- template<typename T, typename ... Types>
- struct is_unordered_map {
- static constexpr bool value = false;
- };
- template<typename ... Types>
- struct is_unordered_map<std::unordered_map<Types...>> {
- static constexpr bool value = true;
- };
- // unordered_set
- // =============
- template<typename T, typename ... Types>
- struct is_unordered_set {
- static constexpr bool value = false;
- };
- template<typename ... Types>
- struct is_unordered_set<std::unordered_set<Types...>> {
- static constexpr bool value = true;
- };
- // unordered_multiset
- // =============
- template<typename T, typename ... Types>
- struct is_unordered_multiset {
- static constexpr bool value = false;
- };
- template<typename ... Types>
- struct is_unordered_multiset<std::unordered_multiset<Types...>> {
- static constexpr bool value = true;
- };
- // unordered_multimap
- // =============
- template<typename T, typename ... Types>
- struct is_unordered_multimap {
- static constexpr bool value = false;
- };
- template<typename ... Types>
- struct is_unordered_multimap<std::unordered_multimap<Types...>> {
- static constexpr bool value = true;
- };
- // multiset
- // =============
- template<typename T, typename ... Types>
- struct is_multiset {
- static constexpr bool value = false;
- };
- template<typename ... Types>
- struct is_multiset<std::multiset<Types...>> {
- static constexpr bool value = true;
- };
- // multimap
- // =============
- template<typename T, typename ... Types>
- struct is_multimap {
- static constexpr bool value = false;
- };
- template<typename ... Types>
- struct is_multimap<std::multimap<Types...>> {
- static constexpr bool value = true;
- };
- // is_container
- // ============
- template <typename T>
- struct is_container {
- static constexpr int value(){
- if (is_set<T>::value) return 1;
- if (is_map<T>::value) return 2;
- if (is_multiset<T>::value) return 3;
- if (is_multimap<T>::value) return 4;
- if (is_unordered_set<T>::value) return 5;
- if (is_unordered_map<T>::value) return 6;
- if (is_unordered_multiset<T>::value) return 7;
- if (is_unordered_multimap<T>::value) return 8;
- if (is_vector<T>::value
- || is_deque<T>::value
- || is_list<T>::value
- || is_forward_list<T>::value) return 0;
- }
- };
- // std::pair for map
- // ============
- template<typename ... Types>
- struct get_pair_value_type1 { typedef int type; };
- template<typename ... Types>
- struct get_pair_value_type2 { typedef int type; };
- template<typename T1, typename T2>
- struct get_pair_value_type1<std::pair<T1, T2>> { typedef T1 type; };
- template<typename T1, typename T2>
- struct get_pair_value_type2<std::pair<T1, T2>> { typedef T2 type; };
- template<typename T1, typename T2>
- struct get_pair_value_type1<std::pair<const T1, T2>> { typedef T1 type; };
- template<typename T1, typename T2>
- struct get_pair_value_type2<std::pair<T1, const T2>> { typedef T2 type; };
- template<typename T1, typename T2>
- struct get_pair_value_type1<std::pair<volatile T1, T2>> { typedef T1 type; };
- template<typename T1, typename T2>
- struct get_pair_value_type2<std::pair<T1, volatile T2>> { typedef T2 type; };
- template<typename T1, typename T2>
- struct get_pair_value_type1<std::pair<const volatile T1, T2>> {
- typedef T1 type;
- };
- template<typename T1, typename T2>
- struct get_pair_value_type2<std::pair<T1, const volatile T2>> {
- typedef T2 type;
- };
- // for set
- // ============
- template<typename T>
- struct get_value_type { typedef T type; };
- template<typename T>
- struct get_value_type<const T> { typedef T type; };
- template<typename T>
- struct get_value_type<volatile T> { typedef T type; };
- template<typename T>
- struct get_value_type<const volatile T> { typedef T type; };
- // MAJOR
- // ============
- template<class C1, class C2>
- bool MergeAssociative(C1* c1, const C2& c2) {
- is_container<C1> Cont1;
- is_container<C2> Cont2;
- if ((Cont1.value() == 1 && Cont2.value() == 2)
- || (Cont1.value() == 1 && Cont2.value() == 6)
- || (Cont1.value() == 2 && Cont2.value() == 5)
- || (Cont1.value() == 2 && Cont2.value() == 1)
- || (Cont1.value() == 3 && Cont2.value() == 4)
- || (Cont1.value() == 3 && Cont2.value() == 8)
- || (Cont1.value() == 4 && Cont2.value() == 7)
- || (Cont1.value() == 4 && Cont2.value() == 3)
- || (Cont1.value() == 5 && Cont2.value() == 2)
- || (Cont1.value() == 5 && Cont2.value() == 6)
- || (Cont1.value() == 6 && Cont2.value() == 1)
- || (Cont1.value() == 6 && Cont2.value() == 5)
- || (Cont1.value() == 7 && Cont2.value() == 4)
- || (Cont1.value() == 7 && Cont2.value() == 8)
- || (Cont1.value() == 8 && Cont2.value() == 3)
- || (Cont1.value() == 8 && Cont2.value() == 7)
- || (Cont1.value() == 0) || (Cont2.value() == 0)
- || (((Cont1.value() <= 6 && Cont1.value() > 4) || Cont1.value() <= 2)
- && ((Cont2.value() > 2 && Cont2.value() <= 3) || Cont2.value() > 6))) {
- return true;
- }
- if (Cont1.value() == 2 || Cont1.value() == 4
- || Cont1.value() == 6 || Cont1.value() == 8) {
- typename decltype(c1->begin())::value_type type1;
- typename decltype(c2.begin())::value_type type2;
- typename get_pair_value_type1<decltype(type1)>::type v1_1;
- typename get_pair_value_type2<decltype(type1)>::type v1_2;
- typename get_pair_value_type1<decltype(type2)>::type v2_1;
- typename get_pair_value_type1<decltype(type2)>::type v2_2;
- if (std::is_same<decltype(v1_1), decltype(v2_1)>::value
- && std::is_same<decltype(v1_2), decltype(v2_2)>::value) {
- return false;
- }
- } else {
- typename decltype(c1->begin())::value_type type1;
- typename decltype(c2.begin())::value_type type2;
- typename get_value_type<decltype(type1)>::type noncv_el1;
- typename get_value_type<decltype(type2)>::type noncv_el2;
- if (std::is_same<decltype(noncv_el1), decltype(noncv_el2)>::value) {
- return false;
- }
- }
- return true;
- }
- template<class C1, class C2>
- bool merge(C1&& c1, C2&& c2) {
- return MergeAssociative(&c1, c2); }
- int main(){
- std::multimap<int, double> a;
- std::unordered_multiset<double> b;
- bool flag = merge(std::vector<int>{4, 2}, std::map<int, char>());
- std::cout << !flag;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement