Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.98 KB | None | 0 0
  1. #include <fstream>
  2. #include <iostream>
  3. #include <type_traits>
  4. #include <map>
  5. #include <unordered_map>
  6. #include <set>
  7. #include <algorithm>
  8. #include <unordered_set>
  9. #include <vector>
  10. #include <deque>
  11. #include <forward_list>
  12. #include <list>
  13. #include <utility>
  14.  
  15. // is_deque
  16. // ========
  17. template<typename T, typename ... Types>
  18. struct is_deque {
  19.     static constexpr bool value = false;
  20. };
  21.  
  22. template<typename ... Types>
  23. struct is_deque<std::deque<Types...>> {
  24.     static constexpr bool value = true;
  25. };
  26.  
  27. // is_forward_list
  28. // ===============
  29. template<typename T, typename ... Types>
  30. struct is_forward_list {
  31.     static constexpr bool value = false;
  32. };
  33.  
  34. template<typename ... Types>
  35. struct is_forward_list<std::forward_list<Types...>> {
  36.     static constexpr bool value = true;
  37. };
  38.  
  39. // list
  40. // ====
  41. template<typename T, typename ... Types>
  42. struct is_list {
  43.     static constexpr bool value = false;
  44. };
  45.  
  46. template<typename ... Types>
  47. struct is_list<std::list<Types...>> {
  48.     static constexpr bool value = true;
  49. };
  50.  
  51. // is_vector
  52. // ======
  53. template<typename T, typename ... Types>
  54. struct is_vector {
  55.     static constexpr bool value = false;
  56. };
  57.  
  58. template<typename ... Types>
  59. struct is_vector<std::vector<Types...>> {
  60.     static constexpr bool value = true;
  61. };
  62.  
  63. // map
  64. // ===
  65. template<typename T, typename ... Types>
  66. struct is_map {
  67.     static constexpr bool value = false;
  68. };
  69.  
  70. template<typename ... Types>
  71. struct is_map<std::map<Types...>> {
  72.     static constexpr bool value = true;
  73. };
  74.  
  75. // set
  76. // ===
  77. template<typename T, typename ... Types>
  78. struct is_set {
  79.     static constexpr bool value = false;
  80. };
  81.  
  82. template<typename ... Types>
  83. struct is_set<std::set<Types...>> {
  84.     static constexpr bool value = true;
  85. };
  86.  
  87. // unordered_map
  88. // =============
  89. template<typename T, typename ... Types>
  90. struct is_unordered_map {
  91.     static constexpr bool value = false;
  92. };
  93.  
  94. template<typename ... Types>
  95. struct is_unordered_map<std::unordered_map<Types...>> {
  96.     static constexpr bool value = true;
  97. };
  98.  
  99. // unordered_set
  100. // =============
  101. template<typename T, typename ... Types>
  102. struct is_unordered_set {
  103.     static constexpr bool value = false;
  104. };
  105.  
  106. template<typename ... Types>
  107. struct is_unordered_set<std::unordered_set<Types...>> {
  108.     static constexpr bool value = true;
  109. };
  110.  
  111. // unordered_multiset
  112. // =============
  113. template<typename T, typename ... Types>
  114. struct is_unordered_multiset {
  115.     static constexpr bool value = false;
  116. };
  117.  
  118. template<typename ... Types>
  119. struct is_unordered_multiset<std::unordered_multiset<Types...>> {
  120.     static constexpr bool value = true;
  121. };
  122.  
  123. // unordered_multimap
  124. // =============
  125. template<typename T, typename ... Types>
  126. struct is_unordered_multimap {
  127.     static constexpr bool value = false;
  128. };
  129.  
  130. template<typename ... Types>
  131. struct is_unordered_multimap<std::unordered_multimap<Types...>> {
  132.     static constexpr bool value = true;
  133. };
  134.  
  135. // multiset
  136. // =============
  137. template<typename T, typename ... Types>
  138. struct is_multiset {
  139.     static constexpr bool value = false;
  140. };
  141.  
  142. template<typename ... Types>
  143. struct is_multiset<std::multiset<Types...>> {
  144.     static constexpr bool value = true;
  145. };
  146.  
  147. // multimap
  148. // =============
  149. template<typename T, typename ... Types>
  150. struct is_multimap {
  151.     static constexpr bool value = false;
  152. };
  153.  
  154. template<typename ... Types>
  155. struct is_multimap<std::multimap<Types...>> {
  156.     static constexpr bool value = true;
  157. };
  158.  
  159. // is_container
  160. // ============
  161. template <typename T>
  162. struct is_container {
  163.     static constexpr int value(){
  164.       if (is_set<T>::value) return 1;
  165.       if (is_map<T>::value) return 2;
  166.       if (is_multiset<T>::value) return 3;
  167.       if (is_multimap<T>::value) return 4;
  168.       if (is_unordered_set<T>::value) return 5;
  169.       if (is_unordered_map<T>::value) return 6;
  170.       if (is_unordered_multiset<T>::value) return 7;
  171.       if (is_unordered_multimap<T>::value) return 8;
  172.       if (is_vector<T>::value
  173.         || is_deque<T>::value
  174.         || is_list<T>::value
  175.         || is_forward_list<T>::value) return 0;
  176.     }
  177. };
  178.  
  179. // std::pair for map
  180. // ============
  181. template<typename ... Types>
  182. struct get_pair_value_type1 { typedef int type; };
  183.  
  184. template<typename ... Types>
  185. struct get_pair_value_type2 { typedef int type; };
  186.  
  187. template<typename T1, typename T2>
  188. struct get_pair_value_type1<std::pair<T1, T2>> { typedef T1 type; };
  189.  
  190. template<typename T1, typename T2>
  191. struct get_pair_value_type2<std::pair<T1, T2>> { typedef T2 type; };
  192.  
  193. template<typename T1, typename T2>
  194. struct get_pair_value_type1<std::pair<const T1, T2>> { typedef T1 type; };
  195.  
  196. template<typename T1, typename T2>
  197. struct get_pair_value_type2<std::pair<T1, const T2>> { typedef T2 type; };
  198.  
  199. template<typename T1, typename T2>
  200. struct get_pair_value_type1<std::pair<volatile T1, T2>> { typedef T1 type; };
  201.  
  202. template<typename T1, typename T2>
  203. struct get_pair_value_type2<std::pair<T1, volatile T2>> { typedef T2 type; };
  204.  
  205. template<typename T1, typename T2>
  206. struct get_pair_value_type1<std::pair<const volatile T1, T2>> {
  207.     typedef T1 type;
  208. };
  209.  
  210. template<typename T1, typename T2>
  211. struct get_pair_value_type2<std::pair<T1, const volatile T2>> {
  212.     typedef T2 type;
  213. };
  214.  
  215. // for set
  216. // ============
  217. template<typename T>
  218. struct get_value_type { typedef T type; };
  219.  
  220. template<typename T>
  221. struct get_value_type<const T> { typedef T type; };
  222.  
  223. template<typename T>
  224. struct get_value_type<volatile T> { typedef T type; };
  225.  
  226. template<typename T>
  227. struct get_value_type<const volatile T> { typedef T type; };
  228.  
  229. // MAJOR
  230. // ============
  231. template<class C1, class C2>
  232. bool MergeAssociative(C1* c1, const C2& c2) {
  233.   is_container<C1> Cont1;
  234.   is_container<C2> Cont2;
  235.   if ((Cont1.value() == 1 && Cont2.value() == 2)
  236.     || (Cont1.value() == 1 && Cont2.value() == 6)
  237.     || (Cont1.value() == 2 && Cont2.value() == 5)
  238.     || (Cont1.value() == 2 && Cont2.value() == 1)
  239.     || (Cont1.value() == 3 && Cont2.value() == 4)
  240.     || (Cont1.value() == 3 && Cont2.value() == 8)
  241.     || (Cont1.value() == 4 && Cont2.value() == 7)
  242.     || (Cont1.value() == 4 && Cont2.value() == 3)
  243.     || (Cont1.value() == 5 && Cont2.value() == 2)
  244.     || (Cont1.value() == 5 && Cont2.value() == 6)
  245.     || (Cont1.value() == 6 && Cont2.value() == 1)
  246.     || (Cont1.value() == 6 && Cont2.value() == 5)
  247.     || (Cont1.value() == 7 && Cont2.value() == 4)
  248.     || (Cont1.value() == 7 && Cont2.value() == 8)
  249.     || (Cont1.value() == 8 && Cont2.value() == 3)
  250.     || (Cont1.value() == 8 && Cont2.value() == 7)
  251.     || (Cont1.value() == 0) || (Cont2.value() == 0)
  252.     || (((Cont1.value() <= 6 && Cont1.value() > 4) || Cont1.value() <= 2)
  253.       && ((Cont2.value() > 2 && Cont2.value() <= 3) || Cont2.value() > 6))) {
  254.       return true;
  255.   }
  256.  
  257.   if (Cont1.value() == 2 || Cont1.value() == 4
  258.     || Cont1.value() == 6 || Cont1.value() == 8) {
  259.       typename decltype(c1->begin())::value_type type1;
  260.       typename decltype(c2.begin())::value_type type2;
  261.  
  262.       typename get_pair_value_type1<decltype(type1)>::type v1_1;
  263.       typename get_pair_value_type2<decltype(type1)>::type v1_2;
  264.       typename get_pair_value_type1<decltype(type2)>::type v2_1;
  265.       typename get_pair_value_type1<decltype(type2)>::type v2_2;
  266.  
  267.       if (std::is_same<decltype(v1_1), decltype(v2_1)>::value
  268.         && std::is_same<decltype(v1_2), decltype(v2_2)>::value) {
  269.           return false;
  270.       }
  271.     } else {
  272.       typename decltype(c1->begin())::value_type type1;
  273.       typename decltype(c2.begin())::value_type type2;
  274.  
  275.       typename get_value_type<decltype(type1)>::type noncv_el1;
  276.       typename get_value_type<decltype(type2)>::type noncv_el2;
  277.  
  278.       if (std::is_same<decltype(noncv_el1), decltype(noncv_el2)>::value) {
  279.         return false;
  280.       }
  281.     }
  282.   return true;
  283. }
  284.  
  285. template<class C1, class C2>
  286. bool merge(C1&& c1, C2&& c2) {
  287.   return MergeAssociative(&c1, c2); }
  288.  
  289. int main(){
  290.   std::multimap<int, double> a;
  291.   std::unordered_multiset<double> b;
  292.  
  293.  bool flag = merge(std::vector<int>{4, 2}, std::map<int, char>());
  294.  
  295.   std::cout << !flag;
  296.   return 0;
  297. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement