]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/unordered/test/unordered/swap_tests.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / unordered / test / unordered / swap_tests.cpp
CommitLineData
7c673cae
FG
1
2// Copyright 2006-2009 Daniel James.
3// Distributed under the Boost Software License, Version 1.0. (See accompanying
4// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
b32b8144 6// clang-format off
7c673cae
FG
7#include "../helpers/prefix.hpp"
8#include <boost/unordered_set.hpp>
9#include <boost/unordered_map.hpp>
10#include "../helpers/postfix.hpp"
b32b8144 11// clang-format on
7c673cae
FG
12
13#include <boost/config.hpp>
14#include <algorithm>
15#include <iterator>
16#include "../helpers/test.hpp"
17#include "../objects/test.hpp"
18#include "../objects/cxx11_allocator.hpp"
19#include "../helpers/random_values.hpp"
20#include "../helpers/tracker.hpp"
21#include "../helpers/invariants.hpp"
22
23#if defined(BOOST_MSVC)
b32b8144 24#pragma warning(disable : 4127) // conditional expression is constant
7c673cae
FG
25#endif
26
b32b8144 27namespace swap_tests {
7c673cae 28
b32b8144 29 test::seed_t initialize_seed(783472);
7c673cae 30
b32b8144
FG
31 template <class X> void swap_test_impl(X& x1, X& x2)
32 {
7c673cae
FG
33 test::ordered<X> tracker1 = test::create_ordered(x1);
34 test::ordered<X> tracker2 = test::create_ordered(x2);
35 tracker1.insert_range(x1.begin(), x1.end());
36 tracker2.insert_range(x2.begin(), x2.end());
37 x1.swap(x2);
38 tracker1.compare(x2);
39 tracker2.compare(x1);
b32b8144 40 }
7c673cae 41
b32b8144
FG
42 template <class X> void swap_tests1(X*, test::random_generator generator)
43 {
7c673cae 44 {
b32b8144 45 test::check_instances check_;
7c673cae 46
b32b8144
FG
47 X x;
48 swap_test_impl(x, x);
7c673cae
FG
49 }
50
51 {
b32b8144 52 test::check_instances check_;
7c673cae 53
b32b8144
FG
54 X x, y;
55 swap_test_impl(x, y);
7c673cae
FG
56 }
57
58 {
b32b8144 59 test::check_instances check_;
7c673cae 60
b32b8144
FG
61 test::random_values<X> v(1000, generator);
62 X x, y(v.begin(), v.end());
63 swap_test_impl(x, y);
64 swap_test_impl(x, y);
7c673cae
FG
65 }
66
67 {
b32b8144 68 test::check_instances check_;
7c673cae 69
b32b8144
FG
70 test::random_values<X> vx(1000, generator), vy(1000, generator);
71 X x(vx.begin(), vx.end()), y(vy.begin(), vy.end());
72 swap_test_impl(x, y);
73 swap_test_impl(x, y);
7c673cae 74 }
b32b8144 75 }
7c673cae 76
b32b8144
FG
77 template <class X> void swap_tests2(X* ptr, test::random_generator generator)
78 {
7c673cae
FG
79 swap_tests1(ptr, generator);
80
81 typedef BOOST_DEDUCED_TYPENAME X::hasher hasher;
82 typedef BOOST_DEDUCED_TYPENAME X::key_equal key_equal;
83 typedef BOOST_DEDUCED_TYPENAME X::allocator_type allocator_type;
84
85 {
b32b8144 86 test::check_instances check_;
7c673cae 87
b32b8144
FG
88 X x(0, hasher(1), key_equal(1));
89 X y(0, hasher(2), key_equal(2));
90 swap_test_impl(x, y);
7c673cae
FG
91 }
92
93 {
b32b8144 94 test::check_instances check_;
7c673cae 95
b32b8144
FG
96 test::random_values<X> v(1000, generator);
97 X x(v.begin(), v.end(), 0, hasher(1), key_equal(1));
98 X y(0, hasher(2), key_equal(2));
99 swap_test_impl(x, y);
7c673cae
FG
100 }
101
102 {
b32b8144 103 test::check_instances check_;
7c673cae 104
b32b8144
FG
105 test::random_values<X> vx(100, generator), vy(50, generator);
106 X x(vx.begin(), vx.end(), 0, hasher(1), key_equal(1));
107 X y(vy.begin(), vy.end(), 0, hasher(2), key_equal(2));
108 swap_test_impl(x, y);
109 swap_test_impl(x, y);
7c673cae
FG
110 }
111
112 {
b32b8144
FG
113 test::force_equal_allocator force_(!allocator_type::is_propagate_on_swap);
114 test::check_instances check_;
115
116 test::random_values<X> vx(50, generator), vy(100, generator);
117 X x(vx.begin(), vx.end(), 0, hasher(), key_equal(), allocator_type(1));
118 X y(vy.begin(), vy.end(), 0, hasher(), key_equal(), allocator_type(2));
119
120 if (allocator_type::is_propagate_on_swap ||
121 x.get_allocator() == y.get_allocator()) {
122 swap_test_impl(x, y);
123 }
7c673cae
FG
124 }
125
126 {
b32b8144
FG
127 test::force_equal_allocator force_(!allocator_type::is_propagate_on_swap);
128 test::check_instances check_;
129
130 test::random_values<X> vx(100, generator), vy(100, generator);
131 X x(vx.begin(), vx.end(), 0, hasher(1), key_equal(1), allocator_type(1));
132 X y(vy.begin(), vy.end(), 0, hasher(2), key_equal(2), allocator_type(2));
7c673cae 133
b32b8144
FG
134 if (allocator_type::is_propagate_on_swap ||
135 x.get_allocator() == y.get_allocator()) {
136 swap_test_impl(x, y);
137 swap_test_impl(x, y);
138 }
139 }
140 }
141
142 boost::unordered_map<test::object, test::object, test::hash, test::equal_to,
143 std::allocator<test::object> >* test_map_std_alloc;
144
145 boost::unordered_set<test::object, test::hash, test::equal_to,
146 test::allocator1<test::object> >* test_set;
147 boost::unordered_multiset<test::object, test::hash, test::equal_to,
148 test::allocator2<test::object> >* test_multiset;
149 boost::unordered_map<test::object, test::object, test::hash, test::equal_to,
150 test::allocator1<test::object> >* test_map;
151 boost::unordered_multimap<test::object, test::object, test::hash,
152 test::equal_to, test::allocator2<test::object> >* test_multimap;
153
154 boost::unordered_set<test::object, test::hash, test::equal_to,
155 test::cxx11_allocator<test::object, test::propagate_swap> >*
7c673cae 156 test_set_prop_swap;
b32b8144
FG
157 boost::unordered_multiset<test::object, test::hash, test::equal_to,
158 test::cxx11_allocator<test::object, test::propagate_swap> >*
7c673cae 159 test_multiset_prop_swap;
b32b8144
FG
160 boost::unordered_map<test::object, test::object, test::hash, test::equal_to,
161 test::cxx11_allocator<test::object, test::propagate_swap> >*
7c673cae 162 test_map_prop_swap;
b32b8144
FG
163 boost::unordered_multimap<test::object, test::object, test::hash,
164 test::equal_to, test::cxx11_allocator<test::object, test::propagate_swap> >*
7c673cae
FG
165 test_multimap_prop_swap;
166
b32b8144
FG
167 boost::unordered_set<test::object, test::hash, test::equal_to,
168 test::cxx11_allocator<test::object, test::no_propagate_swap> >*
7c673cae 169 test_set_no_prop_swap;
b32b8144
FG
170 boost::unordered_multiset<test::object, test::hash, test::equal_to,
171 test::cxx11_allocator<test::object, test::no_propagate_swap> >*
7c673cae 172 test_multiset_no_prop_swap;
b32b8144
FG
173 boost::unordered_map<test::object, test::object, test::hash, test::equal_to,
174 test::cxx11_allocator<test::object, test::no_propagate_swap> >*
7c673cae 175 test_map_no_prop_swap;
b32b8144
FG
176 boost::unordered_multimap<test::object, test::object, test::hash,
177 test::equal_to,
178 test::cxx11_allocator<test::object, test::no_propagate_swap> >*
7c673cae
FG
179 test_multimap_no_prop_swap;
180
b32b8144
FG
181 template <typename T> bool is_propagate(T*)
182 {
7c673cae 183 return T::allocator_type::is_propagate_on_swap;
b32b8144 184 }
7c673cae 185
b32b8144
FG
186 using test::default_generator;
187 using test::generate_collisions;
188 using test::limited_range;
7c673cae 189
b32b8144 190 UNORDERED_AUTO_TEST (check_traits) {
7c673cae
FG
191 BOOST_TEST(!is_propagate(test_set));
192 BOOST_TEST(is_propagate(test_set_prop_swap));
193 BOOST_TEST(!is_propagate(test_set_no_prop_swap));
b32b8144
FG
194 }
195
196 UNORDERED_TEST(
197 swap_tests1, ((test_map_std_alloc)(test_set)(test_multiset)(test_map)(
198 test_multimap)(test_set_prop_swap)(test_multiset_prop_swap)(
199 test_map_prop_swap)(test_multimap_prop_swap)(
200 test_set_no_prop_swap)(test_multiset_no_prop_swap)(
201 test_map_no_prop_swap)(test_multimap_no_prop_swap))(
202 (default_generator)(generate_collisions)(limited_range)))
203
204 UNORDERED_TEST(swap_tests2,
205 ((test_set)(test_multiset)(test_map)(test_multimap)(test_set_prop_swap)(
206 test_multiset_prop_swap)(test_map_prop_swap)(test_multimap_prop_swap)(
207 test_set_no_prop_swap)(test_multiset_no_prop_swap)(test_map_no_prop_swap)(
208 test_multimap_no_prop_swap))(
209 (default_generator)(generate_collisions)(limited_range)))
7c673cae
FG
210}
211RUN_TESTS()