-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathincomplete_test.cpp
More file actions
298 lines (259 loc) · 8.07 KB
/
incomplete_test.cpp
File metadata and controls
298 lines (259 loc) · 8.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
// Copyright 2009 Daniel James.
// Copyright 2022-2023 Christian Mazakas.
// Copyright 2025 Joaquin M Lopez Munoz
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#include "../helpers/unordered.hpp"
#ifdef BOOST_UNORDERED_CFOA_TESTS
#include <boost/unordered/concurrent_flat_set.hpp>
#include <boost/unordered/concurrent_flat_map.hpp>
#include <boost/unordered/concurrent_node_map.hpp>
#include <boost/unordered/concurrent_node_set.hpp>
#endif
#include <utility>
namespace x {
struct D
{
#if defined(BOOST_UNORDERED_CFOA_TESTS)
boost::concurrent_flat_map<D, D> x;
boost::concurrent_node_map<D, D> y;
#elif defined(BOOST_UNORDERED_FOA_TESTS)
boost::unordered_flat_map<D, D> x;
boost::unordered_node_map<D, D> y;
#else
boost::unordered_map<D, D> x;
#endif
};
} // namespace x
namespace incomplete_test {
// Declare, but don't define some types.
struct value;
struct hash;
struct equals;
template <class T> struct allocator;
// Declare some instances
#if defined(BOOST_UNORDERED_CFOA_TESTS)
typedef boost::concurrent_flat_map<value, value, hash, equals,
allocator<std::pair<value const, value> > >
map1;
typedef boost::concurrent_flat_set<value, hash, equals, allocator<value> > set1;
typedef boost::concurrent_node_map<value, value, hash, equals,
allocator<std::pair<value const, value> > >
map2;
typedef boost::concurrent_node_set<value, hash, equals, allocator<value> >
set2;
#elif defined(BOOST_UNORDERED_FOA_TESTS)
typedef boost::unordered_flat_map<value, value, hash, equals,
allocator<std::pair<value const, value> > >
map1;
typedef boost::unordered_flat_set<value, hash, equals, allocator<value> > set1;
typedef boost::unordered_node_map<value, value, hash, equals,
allocator<std::pair<value const, value> > >
map2;
typedef boost::unordered_node_set<value, hash, equals, allocator<value> >
set2;
#else
typedef boost::unordered_map<value, value, hash, equals,
allocator<std::pair<value const, value> > >
map1;
typedef boost::unordered_multimap<value, value, hash, equals,
allocator<std::pair<value const, value> > >
map2;
typedef boost::unordered_set<value, hash, equals, allocator<value> > set1;
typedef boost::unordered_multiset<value, hash, equals, allocator<value> >
set2;
#endif
// Now define the types which are stored as members, as they are needed for
// declaring struct members.
struct hash
{
template <typename T> std::size_t operator()(T const&) const { return 0; }
};
struct equals
{
template <typename T> bool operator()(T const&, T const&) const
{
return true;
}
};
// This is a dubious way to implement an allocator, but good enough
// for this test.
template <typename T> struct allocator : std::allocator<T>
{
allocator() {}
template <typename T2>
allocator(const allocator<T2>& other) : std::allocator<T>(other)
{
}
template <typename T2>
allocator(const std::allocator<T2>& other) : std::allocator<T>(other)
{
}
};
// Declare some members of a structs.
//
// Incomplete hash, equals and allocator aren't here supported at the
// moment.
#ifdef BOOST_UNORDERED_FOA_TESTS
struct struct1
{
boost::unordered_flat_map<struct1, struct1, hash, equals,
allocator<std::pair<struct1 const, struct1> > >
x;
};
struct struct2
{
boost::unordered_node_map<struct2, struct2, hash, equals,
allocator<std::pair<struct2 const, struct2> > >
x;
};
struct struct3
{
boost::unordered_flat_set<struct3, hash, equals, allocator<struct3> > x;
};
struct struct4
{
boost::unordered_node_set<struct4, hash, equals, allocator<struct4> > x;
};
#else
struct struct1
{
boost::unordered_map<struct1, struct1, hash, equals,
allocator<std::pair<struct1 const, struct1> > >
x;
};
struct struct2
{
boost::unordered_multimap<struct2, struct2, hash, equals,
allocator<std::pair<struct2 const, struct2> > >
x;
};
struct struct3
{
boost::unordered_set<struct3, hash, equals, allocator<struct3> > x;
};
struct struct4
{
boost::unordered_multiset<struct4, hash, equals, allocator<struct4> > x;
};
#endif
// Create some instances.
incomplete_test::map1 m1;
#ifndef BOOST_UNORDERED_CFOA_TESTS
incomplete_test::map1::iterator itm1;
incomplete_test::map1::const_iterator citm1;
#ifndef BOOST_UNORDERED_FOA_TESTS
incomplete_test::map1::local_iterator litm1;
incomplete_test::map1::const_local_iterator clitm1;
#endif
#endif
incomplete_test::map2 m2;
#ifndef BOOST_UNORDERED_CFOA_TESTS
incomplete_test::map2::iterator itm2;
incomplete_test::map2::const_iterator citm2;
#ifndef BOOST_UNORDERED_FOA_TESTS
incomplete_test::map2::local_iterator litm2;
incomplete_test::map2::const_local_iterator clitm2;
#endif
#endif
incomplete_test::set1 s1;
#ifndef BOOST_UNORDERED_CFOA_TESTS
incomplete_test::set1::iterator its1;
incomplete_test::set1::const_iterator cits1;
#ifndef BOOST_UNORDERED_FOA_TESTS
incomplete_test::set1::local_iterator lits1;
incomplete_test::set1::const_local_iterator clits1;
#endif
#endif
incomplete_test::set2 s2;
#ifndef BOOST_UNORDERED_CFOA_TESTS
incomplete_test::set2::iterator its2;
incomplete_test::set2::const_iterator cits2;
#ifndef BOOST_UNORDERED_FOA_TESTS
incomplete_test::set2::local_iterator lits2;
incomplete_test::set2::const_local_iterator clits2;
#endif
#endif
incomplete_test::struct1 c1;
incomplete_test::struct2 c2;
incomplete_test::struct3 c3;
incomplete_test::struct4 c4;
// Now define the value type.
struct value
{
};
// Now declare, but don't define, the operators required for comparing
// elements.
std::size_t hash_value(value const&);
bool operator==(value const&, value const&);
std::size_t hash_value(struct1 const&);
std::size_t hash_value(struct2 const&);
std::size_t hash_value(struct3 const&);
std::size_t hash_value(struct4 const&);
bool operator==(struct1 const&, struct1 const&);
bool operator==(struct2 const&, struct2 const&);
bool operator==(struct3 const&, struct3 const&);
bool operator==(struct4 const&, struct4 const&);
// And finally use these
void use_types()
{
incomplete_test::value x;
m1.insert(std::make_pair(x, x));
#ifndef BOOST_UNORDERED_CFOA_TESTS
itm1 = m1.begin();
citm1 = m1.cbegin();
#ifndef BOOST_UNORDERED_FOA_TESTS
litm1 = m1.begin(0);
clitm1 = m1.cbegin(0);
#endif
#endif
m2.insert(std::make_pair(x, x));
#ifndef BOOST_UNORDERED_CFOA_TESTS
itm2 = m2.begin();
citm2 = m2.cbegin();
#ifndef BOOST_UNORDERED_FOA_TESTS
litm2 = m2.begin(0);
clitm2 = m2.cbegin(0);
#endif
#endif
s1.insert(x);
#ifndef BOOST_UNORDERED_CFOA_TESTS
its1 = s1.begin();
cits1 = s1.cbegin();
#ifndef BOOST_UNORDERED_FOA_TESTS
lits1 = s1.begin(0);
clits1 = s1.cbegin(0);
#endif
#endif
s2.insert(x);
#ifndef BOOST_UNORDERED_CFOA_TESTS
its2 = s2.begin();
cits2 = s2.cbegin();
#ifndef BOOST_UNORDERED_FOA_TESTS
lits2 = s2.begin(0);
clits2 = s2.cbegin(0);
#endif
#endif
c1.x.insert(std::make_pair(c1, c1));
c2.x.insert(std::make_pair(c2, c2));
c3.x.insert(c3);
c4.x.insert(c4);
}
// And finally define the operators required for comparing elements.
std::size_t hash_value(value const&) { return 0; }
bool operator==(value const&, value const&) { return true; }
std::size_t hash_value(struct1 const&) { return 0; }
std::size_t hash_value(struct2 const&) { return 0; }
std::size_t hash_value(struct3 const&) { return 0; }
std::size_t hash_value(struct4 const&) { return 0; }
bool operator==(struct1 const&, struct1 const&) { return true; }
bool operator==(struct2 const&, struct2 const&) { return true; }
bool operator==(struct3 const&, struct3 const&) { return true; }
bool operator==(struct4 const&, struct4 const&) { return true; }
} // namespace incomplete_test
int main()
{
// This could just be a compile test, but I like to be able to run these
// things. It's probably irrational, but I find it reassuring.
incomplete_test::use_types();
}