1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // UNSUPPORTED: c++98, c++03, c++11, c++14
14 // class unordered_multiset
16 // template <class H2, class P2>
17 // void merge(unordered_set<key_type, H2, P2, allocator_type>& source);
18 // template <class H2, class P2>
19 // void merge(unordered_set<key_type, H2, P2, allocator_type>&& source);
20 // template <class H2, class P2>
21 // void merge(unordered_multiset<key_type, H2, P2, allocator_type>& source);
22 // template <class H2, class P2>
23 // void merge(unordered_multiset<key_type, H2, P2, allocator_type>&& source);
25 #include <unordered_set>
27 #include "test_macros.h"
31 bool set_equal(const Set& set, Set other)
36 #ifndef TEST_HAS_NO_EXCEPTIONS
42 throw_hasher(bool& should_throw) : should_throw_(should_throw) {}
44 size_t operator()(const T& p) const
48 return std::hash<T>()(p);
56 std::unordered_multiset<int> src{1, 3, 5};
57 std::unordered_multiset<int> dst{2, 4, 5};
59 assert(set_equal(src, {}));
60 assert(set_equal(dst, {1, 2, 3, 4, 5, 5}));
63 #ifndef TEST_HAS_NO_EXCEPTIONS
65 bool do_throw = false;
66 typedef std::unordered_multiset<Counter<int>, throw_hasher<Counter<int>>> set_type;
67 set_type src({1, 3, 5}, 0, throw_hasher<Counter<int>>(do_throw));
68 set_type dst({2, 4, 5}, 0, throw_hasher<Counter<int>>(do_throw));
70 assert(Counter_base::gConstructed == 6);
82 assert(set_equal(src, set_type({1, 3, 5}, 0, throw_hasher<Counter<int>>(do_throw))));
83 assert(set_equal(dst, set_type({2, 4, 5}, 0, throw_hasher<Counter<int>>(do_throw))));
86 assert(Counter_base::gConstructed == 0);
91 bool operator()(const Counter<int>& lhs, const Counter<int>& rhs) const
99 size_t operator()(const Counter<int>& p) const { return std::hash<Counter<int>>()(p); }
102 typedef std::unordered_multiset<Counter<int>, std::hash<Counter<int>>, std::equal_to<Counter<int>>> first_set_type;
103 typedef std::unordered_multiset<Counter<int>, hasher, equal> second_set_type;
104 typedef std::unordered_set<Counter<int>, hasher, equal> third_set_type;
107 first_set_type first{1, 2, 3};
108 second_set_type second{2, 3, 4};
109 third_set_type third{1, 3};
111 assert(Counter_base::gConstructed == 8);
116 assert(set_equal(first, {1, 2, 3, 4, 2, 3, 1, 3}));
117 assert(set_equal(second, {}));
118 assert(set_equal(third, {}));
120 assert(Counter_base::gConstructed == 8);
122 assert(Counter_base::gConstructed == 0);
124 first_set_type first{1, 2, 3};
125 second_set_type second{2, 3, 4};
126 third_set_type third{1, 3};
128 assert(Counter_base::gConstructed == 8);
130 first.merge(std::move(second));
131 first.merge(std::move(third));
133 assert(set_equal(first, {1, 2, 3, 4, 2, 3, 1, 3}));
134 assert(set_equal(second, {}));
135 assert(set_equal(third, {}));
137 assert(Counter_base::gConstructed == 8);
139 assert(Counter_base::gConstructed == 0);
142 std::unordered_multiset<int> first;
144 std::unordered_multiset<int> second;
146 first.merge(std::move(second));
149 std::unordered_set<int> second;
151 first.merge(std::move(second));