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
16 // template <class C2>
17 // void merge(set<Key, C2, Allocator>& source);
18 // template <class C2>
19 // void merge(set<Key, C2, Allocator>&& source);
20 // template <class C2>
21 // void merge(multiset<Key, C2, Allocator>& source);
22 // template <class C2>
23 // void merge(multiset<Key, C2, Allocator>&& source);
27 #include "test_macros.h"
31 bool set_equal(const Set& set, Set other)
36 #ifndef TEST_HAS_NO_EXCEPTIONS
37 struct throw_comparator
41 throw_comparator(bool& should_throw) : should_throw_(should_throw) {}
44 bool operator()(const T& lhs, const T& rhs) const
56 std::multiset<int> src{1, 3, 5};
57 std::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::multiset<Counter<int>, throw_comparator> set_type;
67 set_type src({1, 3, 5}, throw_comparator(do_throw));
68 set_type dst({2, 4, 5}, throw_comparator(do_throw));
70 assert(Counter_base::gConstructed == 6);
82 assert(set_equal(src, set_type({1, 3, 5}, throw_comparator(do_throw))));
83 assert(set_equal(dst, set_type({2, 4, 5}, throw_comparator(do_throw))));
86 assert(Counter_base::gConstructed == 0);
89 comparator() = default;
91 bool operator()(const Counter<int>& lhs, const Counter<int>& rhs) const
97 typedef std::multiset<Counter<int>, std::less<Counter<int>>> first_set_type;
98 typedef std::multiset<Counter<int>, comparator> second_set_type;
99 typedef std::set<Counter<int>, comparator> third_set_type;
102 first_set_type first{1, 2, 3};
103 second_set_type second{2, 3, 4};
104 third_set_type third{1, 3};
106 assert(Counter_base::gConstructed == 8);
111 assert(set_equal(first, {1, 1, 2, 2, 3, 3, 3, 4}));
112 assert(set_equal(second, {}));
113 assert(set_equal(third, {}));
115 assert(Counter_base::gConstructed == 8);
117 assert(Counter_base::gConstructed == 0);
119 first_set_type first{1, 2, 3};
120 second_set_type second{2, 3, 4};
121 third_set_type third{1, 3};
123 assert(Counter_base::gConstructed == 8);
125 first.merge(std::move(second));
126 first.merge(std::move(third));
128 assert(set_equal(first, {1, 1, 2, 2, 3, 3, 3, 4}));
129 assert(set_equal(second, {}));
130 assert(set_equal(third, {}));
132 assert(Counter_base::gConstructed == 8);
134 assert(Counter_base::gConstructed == 0);
137 std::multiset<int> first;
139 std::multiset<int> second;
141 first.merge(std::move(second));
144 std::set<int> second;
146 first.merge(std::move(second));