]>
Commit | Line | Data |
---|---|---|
2e3f9c21 BK |
1 | // -*- C++ -*- |
2 | ||
a5544970 | 3 | // Copyright (C) 2005-2019 Free Software Foundation, Inc. |
2e3f9c21 BK |
4 | // |
5 | // This file is part of the GNU ISO C++ Library. This library is free | |
6 | // software; you can redistribute it and/or modify it under the terms | |
7 | // of the GNU General Public License as published by the Free Software | |
748086b7 | 8 | // Foundation; either version 3, or (at your option) any later |
2e3f9c21 BK |
9 | // version. |
10 | ||
11 | // This library is distributed in the hope that it will be useful, but | |
12 | // WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | // General Public License for more details. | |
15 | ||
16 | // You should have received a copy of the GNU General Public License | |
748086b7 JJ |
17 | // along with this library; see the file COPYING3. If not see |
18 | // <http://www.gnu.org/licenses/>. | |
19 | ||
2e3f9c21 BK |
20 | |
21 | // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. | |
22 | ||
23 | // Permission to use, copy, modify, sell, and distribute this software | |
24 | // is hereby granted without fee, provided that the above copyright | |
25 | // notice appears in all copies, and that both that copyright notice | |
26 | // and this permission notice appear in supporting documentation. None | |
27 | // of the above authors, nor IBM Haifa Research Laboratories, make any | |
28 | // representation about the suitability of this software for any | |
29 | // purpose. It is provided "as is" without express or implied | |
30 | // warranty. | |
31 | ||
32 | /** | |
33 | * @file container_rand_regression_test.tcc | |
34 | * Contains a random regression test for a specific container type. | |
35 | */ | |
36 | ||
37 | #ifndef PB_DS_CONTAINER_RAND_REGRESSION_TEST_TCC | |
38 | #define PB_DS_CONTAINER_RAND_REGRESSION_TEST_TCC | |
39 | ||
40 | // Constructor, copy constructor, assignment and destructor. | |
41 | PB_DS_CLASS_T_DEC | |
42 | PB_DS_CLASS_C_DEC:: | |
f92ab29f CG |
43 | container_rand_regression_test(unsigned long seed, size_t n, size_t m, |
44 | double tp, double ip, double dp, double ep, | |
45 | double cp, double mp, bool disp) | |
2e3f9c21 BK |
46 | : m_seed(seed == 0 ? twister_rand_gen::get_time_determined_seed(): seed), |
47 | m_n(n), m_m(m), m_tp(tp), m_ip(ip), m_dp(dp), m_ep(ep), m_cp(cp), | |
8fc81078 | 48 | m_mp(mp), m_disp(disp), m_p_c(0) |
2e3f9c21 BK |
49 | { } |
50 | ||
51 | PB_DS_CLASS_T_DEC | |
52 | PB_DS_CLASS_C_DEC:: | |
53 | ~container_rand_regression_test() | |
54 | { } | |
55 | ||
56 | PB_DS_CLASS_T_DEC | |
57 | bool | |
58 | PB_DS_CLASS_C_DEC:: | |
59 | default_constructor() | |
60 | { | |
61 | PB_DS_TRACE("default_constructor"); | |
62 | bool done = true; | |
5580c6e7 | 63 | m_alloc.set_probability(m_tp); |
2e3f9c21 BK |
64 | |
65 | try | |
66 | { | |
67 | m_p_c = new Cntnr; | |
68 | } | |
861de21e | 69 | catch(__gnu_cxx::forced_error&) |
2e3f9c21 BK |
70 | { |
71 | done = false; | |
72 | } | |
73 | ||
8fc81078 | 74 | if (m_p_c) |
2e3f9c21 BK |
75 | PB_DS_COND_COMPARE(*m_p_c, m_native_c); |
76 | ||
77 | return done; | |
78 | } | |
79 | ||
80 | PB_DS_CLASS_T_DEC | |
81 | void | |
82 | PB_DS_CLASS_C_DEC:: | |
83 | swap() | |
84 | { | |
85 | PB_DS_TRACE("swap"); | |
5580c6e7 | 86 | m_alloc.set_probability(0); |
2e3f9c21 | 87 | Cntnr* p_c = new Cntnr; |
5580c6e7 | 88 | m_alloc.set_probability(1); |
2e3f9c21 BK |
89 | p_c->swap(*m_p_c); |
90 | std::swap(p_c, m_p_c); | |
91 | delete p_c; | |
92 | PB_DS_COND_COMPARE(*m_p_c, m_native_c); | |
93 | } | |
94 | ||
95 | PB_DS_CLASS_T_DEC | |
96 | bool | |
97 | PB_DS_CLASS_C_DEC:: | |
98 | copy_constructor() | |
99 | { | |
100 | PB_DS_TRACE("copy_constructor"); | |
101 | bool done = true; | |
8fc81078 | 102 | Cntnr* p_c = 0; |
5580c6e7 | 103 | m_alloc.set_probability(m_tp); |
2e3f9c21 | 104 | |
5580c6e7 | 105 | typedef typename allocator_type::group_adjustor adjustor; |
2e3f9c21 BK |
106 | adjustor adjust(m_p_c->size()); |
107 | ||
108 | try | |
109 | { | |
110 | p_c = new Cntnr(*m_p_c); | |
111 | std::swap(p_c, m_p_c); | |
112 | } | |
861de21e | 113 | catch(__gnu_cxx::forced_error&) |
2e3f9c21 BK |
114 | { |
115 | done = false; | |
116 | } | |
117 | ||
118 | delete p_c; | |
119 | PB_DS_COND_COMPARE(*m_p_c, m_native_c); | |
120 | return done; | |
121 | } | |
122 | ||
123 | PB_DS_CLASS_T_DEC | |
124 | bool | |
125 | PB_DS_CLASS_C_DEC:: | |
126 | assignment_operator() | |
127 | { | |
128 | PB_DS_TRACE("assignment operator"); | |
129 | bool done = true; | |
8fc81078 | 130 | Cntnr* p_c = 0; |
5580c6e7 | 131 | m_alloc.set_probability(m_tp); |
2e3f9c21 | 132 | |
5580c6e7 | 133 | typedef typename allocator_type::group_adjustor adjustor; |
2e3f9c21 BK |
134 | adjustor adjust(m_p_c->size()); |
135 | ||
136 | try | |
137 | { | |
138 | p_c = new Cntnr(); | |
139 | *p_c = *m_p_c; | |
140 | std::swap(p_c, m_p_c); | |
141 | } | |
861de21e | 142 | catch(__gnu_cxx::forced_error&) |
2e3f9c21 BK |
143 | { |
144 | done = false; | |
145 | } | |
146 | ||
147 | delete p_c; | |
148 | PB_DS_COND_COMPARE(*m_p_c, m_native_c); | |
149 | return done; | |
150 | } | |
151 | ||
152 | PB_DS_CLASS_T_DEC | |
153 | bool | |
154 | PB_DS_CLASS_C_DEC:: | |
155 | it_constructor() | |
156 | { | |
157 | bool done = true; | |
8fc81078 | 158 | Cntnr* p_c = 0; |
5580c6e7 BK |
159 | m_alloc.set_probability(m_tp); |
160 | typedef typename allocator_type::group_adjustor adjustor; | |
2e3f9c21 BK |
161 | adjustor adjust(m_p_c->size()); |
162 | ||
163 | try | |
164 | { | |
165 | switch(get_next_sub_op(3)) | |
166 | { | |
167 | case 0: | |
168 | p_c = new Cntnr(m_p_c->get_cmp_fn()); | |
169 | m_native_c.clear(); | |
170 | break; | |
171 | case 1: | |
172 | p_c = new Cntnr(m_p_c->begin(), m_p_c->end()); | |
173 | break; | |
174 | case 2: | |
175 | p_c = new Cntnr(m_p_c->begin(), m_p_c->end(), m_p_c->get_cmp_fn()); | |
176 | break; | |
177 | default: | |
178 | _GLIBCXX_THROW_IF(true, "", m_p_c, &m_native_c); | |
179 | }; | |
180 | ||
181 | std::swap(p_c, m_p_c); | |
182 | } | |
861de21e | 183 | catch(__gnu_cxx::forced_error&) |
2e3f9c21 BK |
184 | { |
185 | done = false; | |
186 | } | |
187 | ||
188 | delete p_c; | |
189 | PB_DS_COND_COMPARE(*m_p_c, m_native_c); | |
190 | return done; | |
191 | } | |
192 | ||
193 | ||
194 | // Compare. | |
195 | PB_DS_CLASS_T_DEC | |
196 | void | |
197 | PB_DS_CLASS_C_DEC:: | |
198 | cmp(const Cntnr& c, const native_type& native, const std::string& callfn) | |
199 | { | |
200 | destructor_printer notify(__FUNCTION__); | |
201 | ||
202 | try | |
203 | { | |
5580c6e7 | 204 | m_alloc.set_probability(1); |
f92ab29f | 205 | |
2e3f9c21 BK |
206 | const size_t size = c.size(); |
207 | const size_t native_size = native.size(); | |
208 | _GLIBCXX_THROW_IF(size != native_size, size << " " << native_size, | |
209 | &c, &native); | |
f92ab29f | 210 | |
2e3f9c21 BK |
211 | const bool empty = c.empty(); |
212 | const bool native_empty = native.empty(); | |
f92ab29f | 213 | _GLIBCXX_THROW_IF(empty != native_empty, empty << " " << native_empty, |
2e3f9c21 | 214 | &c, &native); |
f92ab29f | 215 | |
2e3f9c21 BK |
216 | const size_t it_size = std::distance(c.begin(), c.end()); |
217 | _GLIBCXX_THROW_IF(it_size != size, it_size << " " << size, &c, &native); | |
f92ab29f | 218 | |
2e3f9c21 BK |
219 | if (!c.empty()) |
220 | { | |
221 | const std::string native_top = native.top(); | |
222 | const std::string top = test_traits::native_value(c.top()); | |
223 | const bool top_smaller = std::less<std::string>()(top, native_top); | |
224 | const bool top_larger = std::less<std::string>()(native_top, top); | |
f92ab29f | 225 | |
2e3f9c21 BK |
226 | if (top_smaller || top_larger) |
227 | _GLIBCXX_THROW_IF(true, top << " " << native_top, &c, &native); | |
228 | } | |
229 | } | |
230 | catch(...) | |
231 | { | |
232 | _GLIBCXX_THROW_IF(true, "call-fn: " + callfn, &c, &native); | |
233 | } | |
f92ab29f | 234 | |
2e3f9c21 BK |
235 | notify.cancel(); |
236 | } | |
237 | ||
238 | // Operators. | |
239 | PB_DS_CLASS_T_DEC | |
240 | void | |
241 | PB_DS_CLASS_C_DEC:: | |
242 | operator()() | |
243 | { | |
244 | typedef xml_result_set_regression_formatter formatter_type; | |
8fc81078 | 245 | formatter_type* p_fmt = 0; |
2e3f9c21 BK |
246 | if (m_disp) |
247 | p_fmt = new formatter_type(string_form<Cntnr>::name(), | |
248 | string_form<Cntnr>::desc()); | |
249 | ||
250 | m_g.init(m_seed); | |
5580c6e7 | 251 | m_alloc.seed(m_seed); |
2e3f9c21 BK |
252 | |
253 | // The __throw_allocator::_S_label defaults to 0, so to make things | |
254 | // easier and more precise when debugging, start at 1. | |
255 | const size_t starting_label(1); | |
256 | ||
257 | try | |
258 | { | |
259 | prog_bar pb(m_n, std::cout, m_disp); | |
260 | ||
261 | for (m_i = starting_label; m_i <= m_n; ++m_i) | |
262 | { | |
263 | PB_DS_TRACE("Op #" << m_i); | |
264 | ||
265 | // Track allocation from this point only. | |
266 | allocator_type::set_label(m_i); | |
267 | switch(m_i) | |
268 | { | |
269 | case 1: | |
270 | PB_DS_RUN_MTHD(default_constructor); | |
271 | break; | |
272 | case 2: | |
273 | defs(); | |
274 | break; | |
275 | case 3: | |
276 | policy_access(); | |
277 | break; | |
278 | case 4: | |
279 | it_copy(); | |
280 | break; | |
281 | case 5: | |
282 | it_assign(); | |
283 | break; | |
284 | default: | |
285 | switch(get_next_op()) | |
286 | { | |
287 | case insert_op: | |
288 | PB_DS_RUN_MTHD(push) | |
289 | break; | |
290 | case modify_op: | |
291 | PB_DS_RUN_MTHD(modify) | |
292 | break; | |
293 | case erase_op: | |
294 | switch(get_next_sub_op(3)) | |
295 | { | |
296 | case 0: | |
297 | PB_DS_RUN_MTHD(pop) | |
298 | break; | |
299 | case 1: | |
300 | PB_DS_RUN_MTHD(erase_if) | |
301 | break; | |
302 | case 2: | |
303 | PB_DS_RUN_MTHD(erase_it) | |
304 | break; | |
305 | default: | |
306 | _GLIBCXX_THROW_IF(true, "", m_p_c, &m_native_c); | |
307 | } | |
308 | break; | |
309 | case clear_op: | |
310 | PB_DS_RUN_MTHD(clear) | |
311 | break; | |
312 | case other_op: | |
313 | switch(get_next_sub_op(5)) | |
314 | { | |
315 | case 0: | |
316 | swap(); | |
317 | break; | |
318 | case 1: | |
319 | PB_DS_RUN_MTHD(copy_constructor) | |
320 | break; | |
321 | case 2: | |
322 | PB_DS_RUN_MTHD(it_constructor) | |
323 | break; | |
324 | case 3: | |
325 | PB_DS_RUN_MTHD(assignment_operator) | |
326 | break; | |
327 | case 4: | |
328 | PB_DS_RUN_MTHD(split_join) | |
329 | break; | |
330 | default: | |
331 | _GLIBCXX_THROW_IF(true, "", m_p_c, &m_native_c); | |
332 | } | |
333 | break; | |
334 | default: | |
335 | _GLIBCXX_THROW_IF(true, "", m_p_c, &m_native_c); | |
336 | }; | |
337 | } | |
338 | pb.inc(); | |
339 | } | |
340 | } | |
341 | catch (...) | |
342 | { | |
343 | std::cerr << "Failed at index " << m_i << std::endl; | |
344 | delete m_p_c; | |
345 | throw; | |
346 | } | |
347 | ||
348 | // Clean up, then check for allocation by special label, set above. | |
349 | allocator_type::set_label(0); | |
350 | delete m_p_c; | |
351 | ||
f92ab29f CG |
352 | try |
353 | { | |
2e3f9c21 | 354 | for (size_t n = starting_label; n <= m_n; ++n) |
f92ab29f | 355 | m_alloc.check(n); |
2e3f9c21 BK |
356 | } |
357 | catch (std::logic_error& obj) | |
358 | { | |
0462b6aa | 359 | // On fail, check should throw std::logic_error. |
2e3f9c21 BK |
360 | std::cerr << obj.what() << std::endl; |
361 | std::cerr << typeid(Cntnr).name() << std::endl; | |
362 | throw; | |
363 | } | |
364 | ||
365 | // Reset throw probability. | |
5580c6e7 | 366 | m_alloc.set_probability(0); |
2e3f9c21 BK |
367 | |
368 | if (m_disp) | |
369 | { | |
370 | std::cout << std::endl; | |
371 | delete p_fmt; | |
372 | } | |
373 | } | |
374 | ||
375 | PB_DS_CLASS_T_DEC | |
376 | typename PB_DS_CLASS_C_DEC::op | |
377 | PB_DS_CLASS_C_DEC:: | |
378 | get_next_op() | |
379 | { | |
380 | const double prob = m_g.get_prob(); | |
381 | ||
382 | if (prob < m_ip) | |
383 | return insert_op; | |
384 | ||
385 | if (prob < m_ip + m_dp) | |
386 | return modify_op; | |
387 | ||
388 | if (prob < m_ip + m_dp + m_ep) | |
389 | return erase_op; | |
390 | ||
391 | if (prob < m_ip + m_dp + m_ep + m_cp) | |
392 | return clear_op; | |
393 | ||
394 | _GLIBCXX_THROW_IF(prob > 1, prob, m_p_c, &m_native_c); | |
395 | return other_op; | |
396 | } | |
397 | ||
398 | PB_DS_CLASS_T_DEC | |
399 | size_t | |
400 | PB_DS_CLASS_C_DEC:: | |
401 | get_next_sub_op(size_t max) | |
402 | { | |
403 | const double p = m_g.get_prob(); | |
404 | const double delta = 1 / static_cast<double>(max); | |
405 | size_t i = 0; | |
406 | while (true) | |
407 | if (p <= (i + 1) * delta) | |
408 | { | |
409 | _GLIBCXX_THROW_IF(i >= max, i << " " << max, m_p_c, &m_native_c); | |
410 | return i; | |
411 | } | |
412 | else | |
413 | ++i; | |
414 | } | |
415 | ||
416 | // Insert. | |
417 | PB_DS_CLASS_T_DEC | |
418 | bool | |
419 | PB_DS_CLASS_C_DEC:: | |
420 | push() | |
421 | { | |
422 | PB_DS_TRACE("push"); | |
423 | bool done = true; | |
424 | destructor_printer notify(__FUNCTION__); | |
425 | ||
426 | try | |
427 | { | |
5580c6e7 | 428 | m_alloc.set_probability(0); |
2e3f9c21 | 429 | value_type v = test_traits::generate_value(m_g, m_m); |
5580c6e7 | 430 | m_alloc.set_probability(m_tp); |
2e3f9c21 BK |
431 | const typename cntnr::size_type sz = m_p_c->size(); |
432 | m_p_c->push(v); | |
433 | _GLIBCXX_THROW_IF(sz != m_p_c->size() - 1, sz, m_p_c, &m_native_c); | |
434 | m_native_c.push(test_traits::native_value(v)); | |
435 | } | |
861de21e | 436 | catch(__gnu_cxx::forced_error&) |
2e3f9c21 BK |
437 | { |
438 | done = false; | |
439 | } | |
440 | catch(...) | |
441 | { | |
442 | _GLIBCXX_THROW_IF(true, "", m_p_c, &m_native_c); | |
443 | } | |
444 | ||
445 | PB_DS_COND_COMPARE(*m_p_c, m_native_c); | |
446 | notify.cancel(); | |
447 | return done; | |
448 | } | |
449 | ||
450 | ||
451 | // Modify. | |
452 | PB_DS_CLASS_T_DEC | |
453 | bool | |
454 | PB_DS_CLASS_C_DEC:: | |
455 | modify() | |
456 | { | |
457 | PB_DS_TRACE("modify"); | |
458 | destructor_printer notify(__FUNCTION__); | |
459 | ||
460 | bool done = true; | |
461 | try | |
462 | { | |
5580c6e7 | 463 | m_alloc.set_probability(0); |
2e3f9c21 BK |
464 | value_type v = test_traits::generate_value(m_g, m_m); |
465 | ||
5580c6e7 | 466 | m_alloc.set_probability(m_tp); |
2e3f9c21 BK |
467 | typename cntnr::iterator it = m_p_c->begin(); |
468 | std::advance(it, m_g.get_unsigned_long(0, m_p_c->size())); | |
469 | if (it != m_p_c->end()) | |
470 | { | |
471 | typedef typename test_traits::native_value_type native_value_type; | |
472 | native_value_type native_v = test_traits::native_value(*it); | |
473 | native_value_type new_native_v = test_traits::native_value(v); | |
474 | m_p_c->modify(it, v); | |
475 | m_native_c.modify(native_v, new_native_v); | |
476 | } | |
477 | } | |
861de21e | 478 | catch(__gnu_cxx::forced_error&) |
2e3f9c21 BK |
479 | { |
480 | done = false; | |
481 | _GLIBCXX_THROW_IF(true, "", m_p_c, &m_native_c); | |
482 | } | |
483 | ||
484 | PB_DS_COND_COMPARE(*m_p_c, m_native_c); | |
485 | notify.cancel(); | |
486 | return done; | |
487 | } | |
488 | ||
489 | // Clear. | |
490 | PB_DS_CLASS_T_DEC | |
491 | bool | |
492 | PB_DS_CLASS_C_DEC:: | |
493 | clear() | |
494 | { | |
495 | PB_DS_TRACE("clear"); | |
496 | m_p_c->clear(); | |
497 | m_native_c.clear(); | |
498 | return true; | |
499 | } | |
500 | ||
501 | // Erase. | |
502 | PB_DS_CLASS_T_DEC | |
503 | bool | |
504 | PB_DS_CLASS_C_DEC:: | |
505 | pop() | |
506 | { | |
507 | PB_DS_TRACE("pop"); | |
508 | destructor_printer notify(__FUNCTION__); | |
509 | ||
510 | bool done = true; | |
511 | try | |
512 | { | |
5580c6e7 | 513 | m_alloc.set_probability(1); |
2e3f9c21 BK |
514 | if (!m_p_c->empty()) |
515 | { | |
516 | m_p_c->pop(); | |
517 | m_native_c.pop(); | |
518 | } | |
519 | } | |
861de21e | 520 | catch(__gnu_cxx::forced_error&) |
2e3f9c21 BK |
521 | { |
522 | done = false; | |
523 | _GLIBCXX_THROW_IF(true, "", m_p_c, &m_native_c); | |
524 | } | |
525 | ||
526 | PB_DS_COND_COMPARE(*m_p_c, m_native_c); | |
527 | notify.cancel(); | |
528 | return done; | |
529 | } | |
530 | ||
531 | PB_DS_CLASS_T_DEC | |
532 | bool | |
533 | PB_DS_CLASS_C_DEC:: | |
534 | erase_if() | |
535 | { | |
536 | PB_DS_TRACE("erase_if"); | |
537 | destructor_printer notify(__FUNCTION__); | |
538 | ||
539 | bool done = true; | |
540 | try | |
541 | { | |
542 | typedef | |
543 | typename std::iterator_traits<typename cntnr::iterator>::reference | |
544 | it_const_reference; | |
f92ab29f | 545 | |
5580c6e7 | 546 | m_alloc.set_probability(1); |
f92ab29f | 547 | |
2e3f9c21 BK |
548 | typedef |
549 | typename test_traits::template erase_if_fn<value_type> | |
550 | erase_if_fn_t; | |
f92ab29f | 551 | |
2e3f9c21 | 552 | const size_t ersd = m_p_c->erase_if(erase_if_fn_t()); |
f92ab29f | 553 | |
2e3f9c21 BK |
554 | typedef |
555 | typename test_traits::template erase_if_fn<std::string> | |
556 | native_erase_if_fn_t; | |
f92ab29f | 557 | |
2e3f9c21 BK |
558 | const size_t native_ersd = m_native_c.erase_if(native_erase_if_fn_t()); |
559 | ||
560 | _GLIBCXX_THROW_IF(ersd != native_ersd, ersd << " " << native_ersd, | |
561 | m_p_c, &m_native_c); | |
562 | } | |
861de21e | 563 | catch(__gnu_cxx::forced_error&) |
2e3f9c21 | 564 | { |
f92ab29f | 565 | done = false; |
2e3f9c21 BK |
566 | _GLIBCXX_THROW_IF(true, "", m_p_c, &m_native_c); |
567 | } | |
568 | ||
569 | PB_DS_COND_COMPARE(*m_p_c, m_native_c); | |
570 | notify.cancel(); | |
571 | return done; | |
572 | } | |
573 | ||
574 | PB_DS_CLASS_T_DEC | |
575 | bool | |
576 | PB_DS_CLASS_C_DEC:: | |
577 | erase_it() | |
578 | { | |
579 | PB_DS_TRACE("erase_it"); | |
580 | destructor_printer notify(__FUNCTION__); | |
581 | ||
582 | bool done = true; | |
583 | try | |
584 | { | |
f92ab29f CG |
585 | m_alloc.set_probability(1); |
586 | typename cntnr::iterator it = m_p_c->begin(); | |
2e3f9c21 | 587 | std::advance(it, m_g.get_unsigned_long(0, m_p_c->size())); |
f92ab29f | 588 | |
2e3f9c21 BK |
589 | if (it != m_p_c->end()) |
590 | { | |
f92ab29f | 591 | m_native_c.erase(*it); |
2e3f9c21 BK |
592 | m_p_c->erase(it); |
593 | } | |
594 | } | |
861de21e | 595 | catch(__gnu_cxx::forced_error&) |
2e3f9c21 | 596 | { |
f92ab29f | 597 | done = false; |
2e3f9c21 BK |
598 | _GLIBCXX_THROW_IF(true, "", m_p_c, &m_native_c); |
599 | } | |
600 | ||
601 | PB_DS_COND_COMPARE(*m_p_c, m_native_c); | |
602 | notify.cancel(); | |
603 | return done; | |
604 | } | |
605 | ||
606 | // Defs. | |
607 | PB_DS_CLASS_T_DEC | |
608 | void | |
609 | PB_DS_CLASS_C_DEC:: | |
610 | defs() | |
611 | { | |
612 | // General container types. | |
613 | typedef typename Cntnr::size_type test_size_type; | |
614 | typedef typename Cntnr::difference_type difference_type; | |
615 | value_defs(); | |
616 | iterator_defs(); | |
617 | policy_defs(); | |
618 | } | |
619 | ||
620 | PB_DS_CLASS_T_DEC | |
621 | void | |
622 | PB_DS_CLASS_C_DEC:: | |
623 | value_defs() | |
624 | { | |
625 | typedef typename Cntnr::value_type test_value_type; | |
626 | typedef typename Cntnr::reference test_reference; | |
627 | typedef typename Cntnr::const_reference test_const_reference; | |
628 | typedef typename Cntnr::pointer test_pointer; | |
629 | typedef typename Cntnr::const_pointer test_const_pointer; | |
630 | } | |
631 | ||
632 | PB_DS_CLASS_T_DEC | |
633 | void | |
634 | PB_DS_CLASS_C_DEC:: | |
635 | ds_defs() | |
636 | { | |
637 | typedef typename Cntnr::container_category test_container_category; | |
638 | } | |
639 | ||
640 | PB_DS_CLASS_T_DEC | |
641 | void | |
642 | PB_DS_CLASS_C_DEC:: | |
643 | iterator_defs() | |
644 | { | |
645 | typedef typename Cntnr::point_iterator test_point_iterator; | |
a345e45d | 646 | typedef typename Cntnr::point_const_iterator const_test_point_iterator; |
2e3f9c21 BK |
647 | typedef typename Cntnr::iterator test_iterator; |
648 | typedef typename Cntnr::const_iterator const_test_iterator; | |
649 | } | |
650 | ||
651 | PB_DS_CLASS_T_DEC | |
652 | void | |
653 | PB_DS_CLASS_C_DEC:: | |
654 | policy_defs() | |
655 | { | |
656 | typedef typename Cntnr::allocator_type test_allocator; | |
657 | typedef typename Cntnr::cmp_fn test_cmp_fn; | |
658 | } | |
659 | ||
660 | ||
661 | // Policy access. | |
662 | PB_DS_CLASS_T_DEC | |
663 | void | |
664 | PB_DS_CLASS_C_DEC:: | |
665 | policy_access() | |
666 | { | |
667 | PB_DS_TRACE("policy_access"); | |
668 | ||
669 | { | |
670 | typename Cntnr::cmp_fn& r_t = m_p_c->get_cmp_fn(); | |
8fc81078 | 671 | assert(&r_t); |
2e3f9c21 BK |
672 | } |
673 | ||
674 | { | |
675 | const typename Cntnr::cmp_fn& r_t =((const Cntnr& )*m_p_c).get_cmp_fn(); | |
8fc81078 | 676 | assert(&r_t); |
2e3f9c21 BK |
677 | } |
678 | } | |
679 | ||
680 | // Split join. | |
681 | PB_DS_CLASS_T_DEC | |
682 | bool | |
683 | PB_DS_CLASS_C_DEC:: | |
684 | split_join() | |
685 | { | |
686 | PB_DS_TRACE("split_join"); | |
687 | destructor_printer notify(__FUNCTION__); | |
688 | ||
689 | bool done = true; | |
690 | try | |
691 | { | |
5580c6e7 | 692 | m_alloc.set_probability(0); |
2e3f9c21 BK |
693 | Cntnr lhs(*m_p_c); |
694 | Cntnr rhs; | |
695 | native_type native_lhs(m_native_c); | |
5580c6e7 | 696 | m_alloc.set_probability(m_tp); |
f92ab29f | 697 | |
2e3f9c21 BK |
698 | typedef typename test_traits::template erase_if_fn<value_type> split_fn_t; |
699 | lhs.split(split_fn_t(), rhs); | |
f92ab29f | 700 | |
2e3f9c21 BK |
701 | typedef typename test_traits::template erase_if_fn<std::string> |
702 | native_split_fn_t; | |
f92ab29f CG |
703 | |
704 | native_type native_rhs; | |
705 | native_lhs.split(native_split_fn_t(), native_rhs); | |
2e3f9c21 BK |
706 | PB_DS_COND_COMPARE(lhs, native_lhs); |
707 | PB_DS_COND_COMPARE(rhs, native_rhs); | |
f92ab29f | 708 | |
5580c6e7 | 709 | m_alloc.set_probability(m_tp); |
f92ab29f | 710 | |
2e3f9c21 | 711 | if (m_g.get_prob() < 0.5) |
f92ab29f | 712 | lhs.swap(rhs); |
2e3f9c21 | 713 | lhs.join(rhs); |
f92ab29f | 714 | |
2e3f9c21 BK |
715 | _GLIBCXX_THROW_IF(rhs.size() != 0, rhs.size(), m_p_c, &m_native_c); |
716 | _GLIBCXX_THROW_IF(!rhs.empty(), rhs.size(), m_p_c, &m_native_c); | |
717 | } | |
861de21e | 718 | catch(__gnu_cxx::forced_error&) |
2e3f9c21 | 719 | { |
f92ab29f | 720 | done = false; |
2e3f9c21 BK |
721 | const bool b = __gnu_pbds::container_traits<cntnr>::split_join_can_throw; |
722 | _GLIBCXX_THROW_IF(!b, b, m_p_c, &m_native_c); | |
723 | } | |
f92ab29f | 724 | |
2e3f9c21 BK |
725 | PB_DS_COND_COMPARE(*m_p_c, m_native_c); |
726 | notify.cancel(); | |
727 | return done; | |
728 | } | |
729 | ||
730 | // Iterator conversions. | |
731 | PB_DS_CLASS_T_DEC | |
732 | void | |
733 | PB_DS_CLASS_C_DEC:: | |
734 | it_copy() | |
735 | { | |
736 | PB_DS_TRACE("it_copy"); | |
737 | ||
738 | { | |
739 | typename cntnr::iterator it = m_p_c->end(); | |
740 | typename cntnr::const_iterator const_it(it); | |
741 | _GLIBCXX_THROW_IF(const_it != it, "", m_p_c, &m_native_c); | |
742 | _GLIBCXX_THROW_IF(!(const_it == it), "", m_p_c, &m_native_c); | |
743 | } | |
744 | ||
745 | { | |
746 | typename cntnr::const_iterator const_it = m_p_c->end(); | |
a345e45d | 747 | typename cntnr::point_const_iterator const_find_it(const_it); |
2e3f9c21 BK |
748 | _GLIBCXX_THROW_IF(const_find_it != const_it, "", m_p_c, &m_native_c); |
749 | _GLIBCXX_THROW_IF(!(const_find_it == const_it), "", m_p_c, &m_native_c); | |
750 | } | |
751 | ||
752 | { | |
753 | typename cntnr::iterator it = m_p_c->end(); | |
a345e45d | 754 | typename cntnr::point_const_iterator const_find_it1(it); |
2e3f9c21 BK |
755 | _GLIBCXX_THROW_IF(const_find_it1 != it, "", m_p_c, &m_native_c); |
756 | _GLIBCXX_THROW_IF(!(const_find_it1 == it), "", m_p_c, &m_native_c); | |
757 | ||
758 | typename cntnr::point_iterator find_it1(it); | |
759 | _GLIBCXX_THROW_IF(find_it1 != it, "", m_p_c, &m_native_c); | |
760 | _GLIBCXX_THROW_IF(!(find_it1 == it), "", m_p_c, &m_native_c); | |
761 | ||
762 | typename cntnr::point_iterator find_it = m_p_c->end(); | |
a345e45d | 763 | typename cntnr::point_const_iterator const_find_it(find_it); |
2e3f9c21 BK |
764 | _GLIBCXX_THROW_IF(find_it != const_find_it, "", m_p_c, &m_native_c); |
765 | _GLIBCXX_THROW_IF(!(find_it == const_find_it), "", m_p_c, &m_native_c); | |
766 | } | |
767 | } | |
768 | ||
769 | PB_DS_CLASS_T_DEC | |
770 | void | |
771 | PB_DS_CLASS_C_DEC:: | |
772 | it_assign() | |
773 | { | |
774 | PB_DS_TRACE("it_assign"); | |
775 | ||
776 | { | |
777 | typename cntnr::iterator it = m_p_c->end(); | |
778 | typename cntnr::const_iterator const_it; | |
779 | const_it = it; | |
780 | _GLIBCXX_THROW_IF(const_it != it, "", m_p_c, &m_native_c); | |
781 | _GLIBCXX_THROW_IF(!(const_it == it), "", m_p_c, &m_native_c); | |
782 | ||
a345e45d | 783 | typename cntnr::point_const_iterator const_find_it; |
2e3f9c21 BK |
784 | const_find_it = it; |
785 | _GLIBCXX_THROW_IF(const_find_it != it, "", m_p_c, &m_native_c); | |
786 | _GLIBCXX_THROW_IF(!(const_find_it == it), "", m_p_c, &m_native_c); | |
787 | ||
788 | typename cntnr::point_iterator find_it; | |
789 | find_it = it; | |
790 | _GLIBCXX_THROW_IF(find_it != it, "", m_p_c, &m_native_c); | |
791 | _GLIBCXX_THROW_IF(!(find_it == it), "", m_p_c, &m_native_c); | |
792 | } | |
793 | ||
794 | { | |
795 | typename cntnr::const_iterator const_it = m_p_c->end(); | |
a345e45d | 796 | typename cntnr::point_const_iterator const_find_it; |
2e3f9c21 BK |
797 | const_find_it = const_it; |
798 | _GLIBCXX_THROW_IF(const_find_it != const_it, "", m_p_c, &m_native_c); | |
799 | _GLIBCXX_THROW_IF(!(const_find_it == const_it), "", m_p_c, &m_native_c); | |
800 | } | |
801 | ||
802 | { | |
803 | typename cntnr::point_iterator find_it = m_p_c->end(); | |
a345e45d | 804 | typename cntnr::point_const_iterator const_find_it; |
2e3f9c21 BK |
805 | const_find_it = find_it; |
806 | _GLIBCXX_THROW_IF(find_it != const_find_it, "", m_p_c, &m_native_c); | |
807 | _GLIBCXX_THROW_IF(!(find_it == const_find_it), "", m_p_c, &m_native_c); | |
808 | } | |
809 | } | |
810 | ||
811 | ||
812 | // Diagnostics. | |
813 | PB_DS_CLASS_T_DEC | |
814 | void | |
815 | PB_DS_CLASS_C_DEC:: | |
816 | print_container(const native_type& cnt, std::ostream& os) const | |
817 | { | |
5580c6e7 | 818 | m_alloc.set_probability(0); |
2e3f9c21 BK |
819 | native_type cpy(cnt); |
820 | while (!cpy.empty()) | |
821 | { | |
822 | os << cpy.top() << std::endl; | |
823 | cpy.pop(); | |
824 | } | |
825 | } | |
826 | ||
827 | PB_DS_CLASS_T_DEC | |
828 | void | |
829 | PB_DS_CLASS_C_DEC:: | |
830 | print_container(const cntnr& cnt, std::ostream& os) const | |
831 | { | |
832 | typedef typename cntnr::const_iterator const_iterator; | |
5580c6e7 | 833 | m_alloc.set_probability(0); |
2e3f9c21 BK |
834 | for (const_iterator it = cnt.begin(); it != cnt.end(); ++it) |
835 | os << *it << std::endl; | |
836 | } | |
837 | ||
838 | #endif |