[RISCV] Fix mgather -> riscv.masked.strided.load combine not extending indices (...
[llvm-project.git] / libcxx / test / std / containers / associative / multiset / merge.pass.cpp
blob3e99d88995fb826bbfd8cdfa5dc62278bf98eb5c
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14
11 // <set>
13 // class multiset
15 // template <class C2>
16 // void merge(set<Key, C2, Allocator>& source);
17 // template <class C2>
18 // void merge(set<Key, C2, Allocator>&& source);
19 // template <class C2>
20 // void merge(multiset<Key, C2, Allocator>& source);
21 // template <class C2>
22 // void merge(multiset<Key, C2, Allocator>&& source);
24 #include <set>
25 #include <cassert>
26 #include "test_macros.h"
27 #include "Counter.h"
29 template <class Set>
30 bool set_equal(const Set& set, Set other)
32 return set == other;
35 #ifndef TEST_HAS_NO_EXCEPTIONS
36 struct throw_comparator
38 bool& should_throw_;
40 throw_comparator(bool& should_throw) : should_throw_(should_throw) {}
42 template <class T>
43 bool operator()(const T& lhs, const T& rhs) const
45 if (should_throw_)
46 throw 0;
47 return lhs < rhs;
50 #endif
52 int main(int, char**)
55 std::multiset<int> src{1, 3, 5};
56 std::multiset<int> dst{2, 4, 5};
57 dst.merge(src);
58 assert(set_equal(src, {}));
59 assert(set_equal(dst, {1, 2, 3, 4, 5, 5}));
62 #ifndef TEST_HAS_NO_EXCEPTIONS
64 bool do_throw = false;
65 typedef std::multiset<Counter<int>, throw_comparator> set_type;
66 set_type src({1, 3, 5}, throw_comparator(do_throw));
67 set_type dst({2, 4, 5}, throw_comparator(do_throw));
69 assert(Counter_base::gConstructed == 6);
71 do_throw = true;
72 try
74 dst.merge(src);
76 catch (int)
78 do_throw = false;
80 assert(!do_throw);
81 assert(set_equal(src, set_type({1, 3, 5}, throw_comparator(do_throw))));
82 assert(set_equal(dst, set_type({2, 4, 5}, throw_comparator(do_throw))));
84 #endif
85 assert(Counter_base::gConstructed == 0);
86 struct comparator
88 comparator() = default;
90 bool operator()(const Counter<int>& lhs, const Counter<int>& rhs) const
92 return lhs < rhs;
96 typedef std::multiset<Counter<int>, std::less<Counter<int>>> first_set_type;
97 typedef std::multiset<Counter<int>, comparator> second_set_type;
98 typedef std::set<Counter<int>, comparator> third_set_type;
101 first_set_type first{1, 2, 3};
102 second_set_type second{2, 3, 4};
103 third_set_type third{1, 3};
105 assert(Counter_base::gConstructed == 8);
107 first.merge(second);
108 first.merge(third);
110 assert(set_equal(first, {1, 1, 2, 2, 3, 3, 3, 4}));
111 assert(set_equal(second, {}));
112 assert(set_equal(third, {}));
114 assert(Counter_base::gConstructed == 8);
116 assert(Counter_base::gConstructed == 0);
118 first_set_type first{1, 2, 3};
119 second_set_type second{2, 3, 4};
120 third_set_type third{1, 3};
122 assert(Counter_base::gConstructed == 8);
124 first.merge(std::move(second));
125 first.merge(std::move(third));
127 assert(set_equal(first, {1, 1, 2, 2, 3, 3, 3, 4}));
128 assert(set_equal(second, {}));
129 assert(set_equal(third, {}));
131 assert(Counter_base::gConstructed == 8);
133 assert(Counter_base::gConstructed == 0);
136 std::multiset<int> first;
138 std::multiset<int> second;
139 first.merge(second);
140 first.merge(std::move(second));
143 std::set<int> second;
144 first.merge(second);
145 first.merge(std::move(second));
148 return 0;