]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/container/test/static_vector_test.cpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / libs / container / test / static_vector_test.cpp
1 // Boost.Container static_vector
2 // Unit Test
3
4 // Copyright (c) 2012-2013 Adam Wulkiewicz, Lodz, Poland.
5 // Copyright (c) 2012-2013 Andrew Hundt.
6
7 // Use, modification and distribution is subject to the Boost Software License,
8 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
10 #include <boost/core/lightweight_test.hpp>
11 #include <boost/core/no_exceptions_support.hpp>
12 #include <boost/container/vector.hpp>
13 #include <boost/container/list.hpp>
14 #include <boost/container/detail/iterator.hpp>
15 #include "../../intrusive/test/iterator_test.hpp"
16
17 #include "static_vector_test.hpp"
18
19
20 template <typename T, size_t N>
21 void test_ctor_ndc()
22 {
23 static_vector<T, N> s;
24 BOOST_STATIC_ASSERT((static_vector<T, N>::static_capacity) == N);
25 BOOST_TEST_EQ(s.size() , 0u);
26 BOOST_TEST(s.capacity() == N);
27 BOOST_TEST(s.max_size() == N);
28 BOOST_TEST_THROWS( s.at(0u), std::out_of_range );
29 }
30
31 template <typename T, size_t N>
32 void test_ctor_nc(size_t n)
33 {
34 static_vector<T, N> s(n);
35 BOOST_STATIC_ASSERT((static_vector<T, N>::static_capacity) == N);
36 BOOST_TEST(s.size() == n);
37 BOOST_TEST(s.capacity() == N);
38 BOOST_TEST(s.max_size() == N);
39 BOOST_TEST_THROWS( s.at(n), std::out_of_range );
40 if ( 1 < n )
41 {
42 s[0] = 10;
43 BOOST_TEST(T(10) == s[0]);
44 BOOST_TEST(T(10) == s.at(0));
45 s.at(1) = 20;
46 BOOST_TEST(T(20) == s[1]);
47 BOOST_TEST(T(20) == s.at(1));
48 }
49 }
50
51 template <typename T, size_t N>
52 void test_ctor_nd(size_t n, T const& v)
53 {
54 static_vector<T, N> s(n, v);
55 BOOST_STATIC_ASSERT((static_vector<T, N>::static_capacity) == N);
56 BOOST_TEST(s.size() == n);
57 BOOST_TEST(s.capacity() == N);
58 BOOST_TEST_THROWS( s.at(n), std::out_of_range );
59 if ( 1 < n )
60 {
61 BOOST_TEST(v == s[0]);
62 BOOST_TEST(v == s.at(0));
63 BOOST_TEST(v == s[1]);
64 BOOST_TEST(v == s.at(1));
65 s[0] = T(10);
66 BOOST_TEST(T(10) == s[0]);
67 BOOST_TEST(T(10) == s.at(0));
68 s.at(1) = T(20);
69 BOOST_TEST(T(20) == s[1]);
70 BOOST_TEST(T(20) == s.at(1));
71 }
72 }
73
74 void test_support_for_initializer_list()
75 {
76 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
77 {
78 typedef static_vector<int, 2> sv_cap_2;
79 sv_cap_2 sv = {10, 8};
80 BOOST_TEST(10 == sv[0]);
81 BOOST_TEST(8 == sv[1]);
82
83 BOOST_TEST_THROWS(sv_cap_2({1, 1, 1}), std::bad_alloc);
84 }
85
86 {
87 static_vector<int, 2> sv;
88 sv.assign({1, 2});
89 BOOST_TEST(1 == sv[0]);
90 BOOST_TEST(2 == sv[1]);
91
92 BOOST_TEST_THROWS(sv.assign({1, 2, 3}), std::bad_alloc);
93
94 static_vector<int, 3> greaterThanSv = {1, 2, 3};
95 BOOST_TEST_THROWS(sv = greaterThanSv, std::bad_alloc);
96 }
97
98 {
99 static_vector<int, 2> sv;
100 sv.insert(sv.begin(), {99, 95});
101 BOOST_TEST(99 == sv[0]);
102 BOOST_TEST(95 == sv[1]);
103
104 BOOST_TEST_THROWS(sv.insert(sv.begin(), {101, 102, 103}), std::bad_alloc);
105 }
106 #endif
107 }
108
109 template <typename T, size_t N>
110 void test_resize_nc(size_t n)
111 {
112 static_vector<T, N> s;
113
114 s.resize(n);
115 BOOST_TEST(s.size() == n);
116 BOOST_TEST(s.capacity() == N);
117 BOOST_TEST_THROWS( s.at(n), std::out_of_range );
118 if ( 1 < n )
119 {
120 s[0] = 10;
121 BOOST_TEST(T(10) == s[0]);
122 BOOST_TEST(T(10) == s.at(0));
123 s.at(1) = 20;
124 BOOST_TEST(T(20) == s[1]);
125 BOOST_TEST(T(20) == s.at(1));
126 }
127 }
128
129 template <typename T, size_t N>
130 void test_resize_nd(size_t n, T const& v)
131 {
132 static_vector<T, N> s;
133
134 s.resize(n, v);
135 BOOST_TEST(s.size() == n);
136 BOOST_TEST(s.capacity() == N);
137 BOOST_TEST_THROWS( s.at(n), std::out_of_range );
138 if ( 1 < n )
139 {
140 BOOST_TEST(v == s[0]);
141 BOOST_TEST(v == s.at(0));
142 BOOST_TEST(v == s[1]);
143 BOOST_TEST(v == s.at(1));
144 s[0] = T(10);
145 BOOST_TEST(T(10) == s[0]);
146 BOOST_TEST(T(10) == s.at(0));
147 s.at(1) = T(20);
148 BOOST_TEST(T(20) == s[1]);
149 BOOST_TEST(T(20) == s.at(1));
150 }
151 }
152
153 template <typename T, size_t N>
154 void test_push_back_nd()
155 {
156 static_vector<T, N> s;
157
158 BOOST_TEST(s.size() == 0);
159 BOOST_TEST_THROWS( s.at(0), std::out_of_range );
160
161 for ( size_t i = 0 ; i < N ; ++i )
162 {
163 T t(static_cast<int>(i));
164 s.push_back(t);
165 BOOST_TEST(s.size() == i + 1);
166 BOOST_TEST_THROWS( s.at(i + 1), std::out_of_range );
167 BOOST_TEST(T((int)i) == s.at(i));
168 BOOST_TEST(T((int)i) == s[i]);
169 BOOST_TEST(T((int)i) == s.back());
170 BOOST_TEST(T(0) == s.front());
171 BOOST_TEST(T((int)i) == *(s.data() + i));
172 }
173 }
174
175 template <typename T, size_t N>
176 void test_pop_back_nd()
177 {
178 static_vector<T, N> s;
179
180 for ( size_t i = 0 ; i < N ; ++i )
181 {
182 T t((int)i);
183 s.push_back(t);
184 }
185
186 for ( size_t i = N ; i > 1 ; --i )
187 {
188 s.pop_back();
189 BOOST_TEST(s.size() == i - 1);
190 BOOST_TEST_THROWS( s.at(i - 1), std::out_of_range );
191 BOOST_TEST(T((int)i - 2) == s.at(i - 2));
192 BOOST_TEST(T((int)i - 2) == s[i - 2]);
193 BOOST_TEST(T((int)i - 2) == s.back());
194 BOOST_TEST(T(0) == s.front());
195 }
196 }
197
198 template <typename It1, typename It2>
199 void test_compare_ranges(It1 first1, It1 last1, It2 first2, It2 last2)
200 {
201 BOOST_TEST(boost::container::iterator_distance(first1, last1) == boost::container::iterator_distance(first2, last2));
202 for ( ; first1 != last1 && first2 != last2 ; ++first1, ++first2 )
203 BOOST_TEST(*first1 == *first2);
204 }
205
206 template <typename T, size_t N, typename C>
207 void test_copy_and_assign(C const& c)
208 {
209 {
210 static_vector<T, N> s(c.begin(), c.end());
211 BOOST_TEST(s.size() == c.size());
212 test_compare_ranges(s.begin(), s.end(), c.begin(), c.end());
213 }
214 {
215 static_vector<T, N> s;
216 BOOST_TEST(0 == s.size());
217 s.assign(c.begin(), c.end());
218 BOOST_TEST(s.size() == c.size());
219 test_compare_ranges(s.begin(), s.end(), c.begin(), c.end());
220 }
221 }
222
223 template <typename T, size_t N>
224 void test_copy_and_assign_nd(T const& val)
225 {
226 static_vector<T, N> s;
227 vector<T> v;
228 list<T> l;
229
230 for ( size_t i = 0 ; i < N ; ++i )
231 {
232 T t((int)i);
233 s.push_back(t);
234 v.push_back(t);
235 l.push_back(t);
236 }
237 // copy ctor
238 {
239 static_vector<T, N> s1(s);
240 BOOST_TEST(s.size() == s1.size());
241 test_compare_ranges(s.begin(), s.end(), s1.begin(), s1.end());
242 }
243 // copy assignment
244 {
245 static_vector<T, N> s1;
246 BOOST_TEST(0 == s1.size());
247 s1 = s;
248 BOOST_TEST(s.size() == s1.size());
249 test_compare_ranges(s.begin(), s.end(), s1.begin(), s1.end());
250 }
251
252 // ctor(Iter, Iter) and assign(Iter, Iter)
253 test_copy_and_assign<T, N>(s);
254 test_copy_and_assign<T, N>(v);
255 test_copy_and_assign<T, N>(l);
256
257 // assign(N, V)
258 {
259 static_vector<T, N> s1(s);
260 test_compare_ranges(s.begin(), s.end(), s1.begin(), s1.end());
261 vector<T> a(N, val);
262 s1.assign(N, val);
263 test_compare_ranges(a.begin(), a.end(), s1.begin(), s1.end());
264 }
265 }
266
267 template <typename T, size_t N>
268 void test_iterators_nd()
269 {
270 static_vector<T, N> s;
271 vector<T> v;
272
273 for ( size_t i = 0 ; i < N ; ++i )
274 {
275 s.push_back(T((int)i));
276 v.push_back(T((int)i));
277 }
278
279 test_compare_ranges(s.begin(), s.end(), v.begin(), v.end());
280 test_compare_ranges(s.rbegin(), s.rend(), v.rbegin(), v.rend());
281
282 s.assign(v.rbegin(), v.rend());
283
284 test_compare_ranges(s.begin(), s.end(), v.rbegin(), v.rend());
285 test_compare_ranges(s.rbegin(), s.rend(), v.begin(), v.end());
286 }
287
288 template <typename T, size_t N>
289 void test_erase_nd()
290 {
291 static_vector<T, N> s;
292 typedef typename static_vector<T, N>::iterator It;
293
294 for ( size_t i = 0 ; i < N ; ++i )
295 s.push_back(T((int)i));
296
297 // erase(pos)
298 {
299 for ( size_t i = 0 ; i < N ; ++i )
300 {
301 static_vector<T, N> s1(s);
302 It it = s1.erase(s1.begin() + i);
303 BOOST_TEST(s1.begin() + i == it);
304 BOOST_TEST(s1.size() == N - 1);
305 for ( size_t j = 0 ; j < i ; ++j )
306 BOOST_TEST(s1[j] == T((int)j));
307 for ( size_t j = i+1 ; j < N ; ++j )
308 BOOST_TEST(s1[j-1] == T((int)j));
309 }
310 }
311 // erase(first, last)
312 {
313 size_t n = N/3;
314 for ( size_t i = 0 ; i <= N ; ++i )
315 {
316 static_vector<T, N> s1(s);
317 size_t removed = i + n < N ? n : N - i;
318 It it = s1.erase(s1.begin() + i, s1.begin() + i + removed);
319 BOOST_TEST(s1.begin() + i == it);
320 BOOST_TEST(s1.size() == N - removed);
321 for ( size_t j = 0 ; j < i ; ++j )
322 BOOST_TEST(s1[j] == T((int)j));
323 for ( size_t j = i+n ; j < N ; ++j )
324 BOOST_TEST(s1[j-n] == T((int)j));
325 }
326 }
327 }
328
329 template <typename T, size_t N, typename SV, typename C>
330 void test_insert(SV const& s, C const& c)
331 {
332 size_t h = N/2;
333 size_t n = size_t(h/1.5f);
334
335 for ( size_t i = 0 ; i <= h ; ++i )
336 {
337 static_vector<T, N> s1(s);
338
339 typename C::const_iterator it = c.begin();
340 boost::container::iterator_advance(it, n);
341 typename static_vector<T, N>::iterator
342 it1 = s1.insert(s1.begin() + i, c.begin(), it);
343
344 BOOST_TEST(s1.begin() + i == it1);
345 BOOST_TEST(s1.size() == h+n);
346 for ( size_t j = 0 ; j < i ; ++j )
347 BOOST_TEST(s1[j] == T((int)j));
348 for ( size_t j = 0 ; j < n ; ++j )
349 BOOST_TEST(s1[j+i] == T(100 + (int)j));
350 for ( size_t j = 0 ; j < h-i ; ++j )
351 BOOST_TEST(s1[j+i+n] == T((int)j+(int)i));
352 }
353 }
354
355 template <typename T, size_t N>
356 void test_insert_nd(T const& val)
357 {
358 size_t h = N/2;
359
360 static_vector<T, N> s, ss;
361 vector<T> v;
362 list<T> l;
363
364 typedef typename static_vector<T, N>::iterator It;
365
366 for ( size_t i = 0 ; i < h ; ++i )
367 {
368 s.push_back(T((int)i));
369 ss.push_back(T(100 + (int)i));
370 v.push_back(T(100 + (int)i));
371 l.push_back(T(100 + (int)i));
372 }
373
374 // insert(pos, val)
375 {
376 for ( size_t i = 0 ; i <= h ; ++i )
377 {
378 static_vector<T, N> s1(s);
379 It it = s1.insert(s1.begin() + i, val);
380 BOOST_TEST(s1.begin() + i == it);
381 BOOST_TEST(s1.size() == h+1);
382 for ( size_t j = 0 ; j < i ; ++j )
383 BOOST_TEST(s1[j] == T((int)j));
384 BOOST_TEST(s1[i] == val);
385 for ( size_t j = 0 ; j < h-i ; ++j )
386 BOOST_TEST(s1[j+i+1] == T((int)j+(int)i));
387 }
388 }
389 // insert(pos, n, val)
390 {
391 size_t n = size_t(h/1.5f);
392 for ( size_t i = 0 ; i <= h ; ++i )
393 {
394 static_vector<T, N> s1(s);
395 It it = s1.insert(s1.begin() + i, n, val);
396 BOOST_TEST(s1.begin() + i == it);
397 BOOST_TEST(s1.size() == h+n);
398 for ( size_t j = 0 ; j < i ; ++j )
399 BOOST_TEST(s1[j] == T((int)j));
400 for ( size_t j = 0 ; j < n ; ++j )
401 BOOST_TEST(s1[j+i] == val);
402 for ( size_t j = 0 ; j < h-i ; ++j )
403 BOOST_TEST(s1[j+i+n] == T((int)j+(int)i));
404 }
405 }
406 // insert(pos, first, last)
407 test_insert<T, N>(s, ss);
408 test_insert<T, N>(s, v);
409 test_insert<T, N>(s, l);
410 }
411
412 template <typename T>
413 void test_capacity_0_nd()
414 {
415 static_vector<T, 10> v(5u, T(0));
416
417 typedef static_vector<T, 0> static_vector_0_t;
418 static_vector_0_t s;
419 BOOST_TEST(s.size() == 0);
420 BOOST_TEST(s.capacity() == 0);
421 BOOST_TEST_THROWS(s.at(0), std::out_of_range);
422 BOOST_TEST_THROWS(s.resize(5u, T(0)), std::bad_alloc);
423 BOOST_TEST_THROWS(s.push_back(T(0)), std::bad_alloc);
424 BOOST_TEST_THROWS(s.insert(s.end(), T(0)), std::bad_alloc);
425 BOOST_TEST_THROWS(s.insert(s.end(), 5u, T(0)), std::bad_alloc);
426 BOOST_TEST_THROWS(s.insert(s.end(), v.begin(), v.end()), std::bad_alloc);
427 BOOST_TEST_THROWS(s.assign(v.begin(), v.end()), std::bad_alloc);
428 BOOST_TEST_THROWS(s.assign(5u, T(0)), std::bad_alloc);
429 BOOST_TEST_THROWS(s.assign(5u, T(0)), std::bad_alloc);
430 BOOST_TEST_THROWS(static_vector_0_t s2(v.begin(), v.end()), std::bad_alloc);
431 BOOST_TEST_THROWS(static_vector_0_t s1(5u, T(0)), std::bad_alloc);
432 }
433
434 template <typename T, size_t N>
435 void test_exceptions_nd()
436 {
437 static_vector<T, N> v(N, T(0));
438 typedef static_vector<T, N/2> static_vector_n_half_t;
439 static_vector_n_half_t s(N/2, T(0));
440
441 BOOST_TEST_THROWS(s.resize(N, T(0)), std::bad_alloc);
442 BOOST_TEST_THROWS(s.push_back(T(0)), std::bad_alloc);
443 BOOST_TEST_THROWS(s.insert(s.end(), T(0)), std::bad_alloc);
444 BOOST_TEST_THROWS(s.insert(s.end(), 1, T(0)), std::bad_alloc);
445 BOOST_TEST_THROWS(s.insert(s.end(), v.begin(), v.end()), std::bad_alloc);
446 BOOST_TEST_THROWS(s.assign(v.begin(), v.end()), std::bad_alloc);
447 BOOST_TEST_THROWS(s.assign(N, T(0)), std::bad_alloc);
448 BOOST_TEST_THROWS(static_vector_n_half_t s2(v.begin(), v.end()), std::bad_alloc);
449 BOOST_TEST_THROWS(static_vector_n_half_t s1(N/2+1, T(0)), std::bad_alloc);
450 }
451
452 template <typename T, size_t N>
453 void test_swap_and_move_nd()
454 {
455 {
456 static_vector<T, N> v1, v2, v3, v4;
457 static_vector<T, N> s1, s2;
458 static_vector<T, N> s4;
459
460 for (size_t i = 0 ; i < N ; ++i )
461 {
462 v1.push_back(T((int)i));
463 v2.push_back(T((int)i));
464 v3.push_back(T((int)i));
465 v4.push_back(T((int)i));
466 }
467 for (size_t i = 0 ; i < N/2 ; ++i )
468 {
469 s1.push_back(T(100 + (int)i));
470 s2.push_back(T(100 + (int)i));
471 s4.push_back(T(100 + (int)i));
472 }
473
474 s1.swap(v1);
475 s2 = boost::move(v2);
476 static_vector<T, N> s3(boost::move(v3));
477 s4.swap(v4);
478
479 BOOST_TEST(v1.size() == N/2);
480 BOOST_TEST(s1.size() == N);
481 BOOST_TEST(v2.size() == 0);
482 BOOST_TEST(s2.size() == N);
483 BOOST_TEST(v3.size() == 0);
484 BOOST_TEST(s3.size() == N);
485 BOOST_TEST(v4.size() == N/2);
486 BOOST_TEST(s4.size() == N);
487 for (size_t i = 0 ; i < N/2 ; ++i )
488 {
489 BOOST_TEST(v1[i] == T(100 + (int)i));
490 BOOST_TEST(v4[i] == T(100 + (int)i));
491 }
492 for (size_t i = 0 ; i < N ; ++i )
493 {
494 BOOST_TEST(s1[i] == T((int)i));
495 BOOST_TEST(s2[i] == T((int)i));
496 BOOST_TEST(s3[i] == T((int)i));
497 BOOST_TEST(s4[i] == T((int)i));
498 }
499 }
500 {
501 static_vector<T, N> v1, v2, v3;
502 static_vector<T, N/2> s1, s2, s3;
503
504 for (size_t i = 0 ; i < N/2 ; ++i )
505 {
506 v1.push_back(T((int)i));
507 v2.push_back(T((int)i));
508 v3.push_back(T((int)i));
509 }
510 for (size_t i = 0 ; i < N/3 ; ++i )
511 {
512 s1.push_back(T(100 + (int)i));
513 s2.push_back(T(100 + (int)i));
514 }
515
516 s1.swap(v1);
517 s3 = v2;
518 s2 = boost::move(v2);
519 static_vector<T, N/2> s4(boost::move(v3));
520
521 BOOST_TEST(v1.size() == N/3);
522 BOOST_TEST(s1.size() == N/2);
523 //iG moving does not imply emptying source
524 //BOOST_TEST(v2.size() == 0);
525 BOOST_TEST(s2.size() == N/2);
526 BOOST_TEST(s3.size() == N/2);
527 //iG moving does not imply emptying source
528 //BOOST_TEST(v3.size() == 0);
529 BOOST_TEST(s4.size() == N/2);
530 for (size_t i = 0 ; i < N/3 ; ++i )
531 BOOST_TEST(v1[i] == T(100 + (int)i));
532 for (size_t i = 0 ; i < N/2 ; ++i )
533 {
534 BOOST_TEST(s1[i] == T((int)i));
535 BOOST_TEST(s2[i] == T((int)i));
536 BOOST_TEST(s3[i] == T((int)i));
537 BOOST_TEST(s4[i] == T((int)i));
538 }
539 }
540 {
541 typedef static_vector<T, N/2> small_vector_t;
542 static_vector<T, N> v(N, T(0));
543 small_vector_t s(N/2, T(1));
544 BOOST_TEST_THROWS(s.swap(v), std::bad_alloc);
545 v.resize(N, T(0));
546 BOOST_TEST_THROWS(s = boost::move(v), std::bad_alloc);
547 BOOST_TEST_THROWS(s = v, std::bad_alloc);
548 v.resize(N, T(0));
549 BOOST_TEST_THROWS(small_vector_t s2(boost::move(v)), std::bad_alloc);
550 }
551 }
552
553 template <typename T, size_t N>
554 void test_emplace_0p()
555 {
556 //emplace_back()
557 {
558 static_vector<T, N> v;
559
560 for (int i = 0 ; i < int(N) ; ++i )
561 v.emplace_back();
562 BOOST_TEST(v.size() == N);
563 BOOST_TEST_THROWS(v.emplace_back(), std::bad_alloc);
564 }
565 }
566
567 template <typename T, size_t N>
568 void test_emplace_2p()
569 {
570 //emplace_back(pos, int, int)
571 {
572 static_vector<T, N> v;
573
574 for (int i = 0 ; i < int(N) ; ++i )
575 v.emplace_back(i, 100 + i);
576 BOOST_TEST(v.size() == N);
577 BOOST_TEST_THROWS(v.emplace_back((int)N, 100 + (int)N), std::bad_alloc);
578 BOOST_TEST(v.size() == N);
579 for (int i = 0 ; i < int(N) ; ++i )
580 BOOST_TEST(v[i] == T(i, 100 + i));
581 }
582
583 // emplace(pos, int, int)
584 {
585 typedef typename static_vector<T, N>::iterator It;
586
587 int h = N / 2;
588
589 static_vector<T, N> v;
590 for ( int i = 0 ; i < h ; ++i )
591 v.emplace_back(i, 100 + i);
592
593 for ( int i = 0 ; i <= h ; ++i )
594 {
595 static_vector<T, N> vv(v);
596 It it = vv.emplace(vv.begin() + i, i+100, i+200);
597 BOOST_TEST(vv.begin() + i == it);
598 BOOST_TEST(vv.size() == size_t(h+1));
599 for ( int j = 0 ; j < i ; ++j )
600 BOOST_TEST(vv[j] == T(j, j+100));
601 BOOST_TEST(vv[i] == T(i+100, i+200));
602 for ( int j = 0 ; j < h-i ; ++j )
603 BOOST_TEST(vv[j+i+1] == T(j+i, j+i+100));
604 }
605 }
606 }
607
608 template <typename T, size_t N>
609 void test_sv_elem(T const& t)
610 {
611 typedef static_vector<T, N> V;
612
613 static_vector<V, N> v;
614
615 v.push_back(V(N/2, t));
616 V vvv(N/2, t);
617 v.push_back(boost::move(vvv));
618 v.insert(v.begin(), V(N/2, t));
619 v.insert(v.end(), V(N/2, t));
620 v.emplace_back(N/2, t);
621 }
622
623 bool default_init_test()//Test for default initialization
624 {
625 const std::size_t Capacity = 100;
626
627 typedef static_vector<int, Capacity> di_vector_t;
628
629 {
630 di_vector_t v(Capacity, default_init);
631 }
632 {
633 di_vector_t v;
634 int *p = v.data();
635
636 for(std::size_t i = 0; i != Capacity; ++i, ++p){
637 *p = static_cast<int>(i);
638 }
639
640 //Destroy the vector, p still pointing to the storage
641 v.~di_vector_t();
642
643 di_vector_t &rv = *::new(&v)di_vector_t(Capacity, default_init);
644 di_vector_t::iterator it = rv.begin();
645
646 for(std::size_t i = 0; i != Capacity; ++i, ++it){
647 if(*it != static_cast<int>(i))
648 return false;
649 }
650
651 v.~di_vector_t();
652 }
653 {
654 di_vector_t v;
655
656 int *p = v.data();
657 for(std::size_t i = 0; i != Capacity; ++i, ++p){
658 *p = static_cast<int>(i+100);
659 }
660
661 v.resize(Capacity, default_init);
662
663 di_vector_t::iterator it = v.begin();
664 for(std::size_t i = 0; i != Capacity; ++i, ++it){
665 if(*it != static_cast<int>(i+100))
666 return false;
667 }
668 }
669
670 return true;
671 }
672
673
674 int main(int, char* [])
675 {
676 using boost::container::test::movable_and_copyable_int;
677 using boost::container::test::produce_movable_and_copyable_int;
678 BOOST_TEST(counting_value::count() == 0);
679
680 test_ctor_ndc<int, 10>();
681 test_ctor_ndc<value_ndc, 10>();
682 test_ctor_ndc<counting_value, 10>();
683 BOOST_TEST(counting_value::count() == 0);
684 test_ctor_ndc<movable_and_copyable_int, 10>();
685
686 test_ctor_nc<int, 10>(5);
687 test_ctor_nc<value_nc, 10>(5);
688 test_ctor_nc<counting_value, 10>(5);
689 BOOST_TEST(counting_value::count() == 0);
690 test_ctor_nc<movable_and_copyable_int, 10>(5);
691
692 test_ctor_nd<int, 10>(5, 1);
693 test_ctor_nd<value_nd, 10>(5, value_nd(1));
694 test_ctor_nd<counting_value, 10>(5, counting_value(1));
695 BOOST_TEST(counting_value::count() == 0);
696 test_ctor_nd<movable_and_copyable_int, 10>(5, produce_movable_and_copyable_int());
697
698 test_resize_nc<int, 10>(5);
699 test_resize_nc<value_nc, 10>(5);
700 test_resize_nc<counting_value, 10>(5);
701 BOOST_TEST(counting_value::count() == 0);
702 test_resize_nc<movable_and_copyable_int, 10>(5);
703
704 test_resize_nd<int, 10>(5, 1);
705 test_resize_nd<value_nd, 10>(5, value_nd(1));
706 test_resize_nd<counting_value, 10>(5, counting_value(1));
707 BOOST_TEST(counting_value::count() == 0);
708 test_resize_nd<movable_and_copyable_int, 10>(5, produce_movable_and_copyable_int());
709
710 test_push_back_nd<int, 10>();
711 test_push_back_nd<value_nd, 10>();
712 test_push_back_nd<counting_value, 10>();
713 BOOST_TEST(counting_value::count() == 0);
714 test_push_back_nd<movable_and_copyable_int, 10>();
715
716 test_pop_back_nd<int, 10>();
717 test_pop_back_nd<value_nd, 10>();
718 test_pop_back_nd<counting_value, 10>();
719 BOOST_TEST(counting_value::count() == 0);
720 test_pop_back_nd<movable_and_copyable_int, 10>();
721
722 test_copy_and_assign_nd<int, 10>(1);
723 test_copy_and_assign_nd<value_nd, 10>(value_nd(1));
724 test_copy_and_assign_nd<counting_value, 10>(counting_value(1));
725 BOOST_TEST(counting_value::count() == 0);
726 test_copy_and_assign_nd<movable_and_copyable_int, 10>(produce_movable_and_copyable_int());
727
728 test_iterators_nd<int, 10>();
729 test_iterators_nd<value_nd, 10>();
730 test_iterators_nd<counting_value, 10>();
731 BOOST_TEST(counting_value::count() == 0);
732 test_iterators_nd<movable_and_copyable_int, 10>();
733
734 test_erase_nd<int, 10>();
735 test_erase_nd<value_nd, 10>();
736 test_erase_nd<counting_value, 10>();
737 BOOST_TEST(counting_value::count() == 0);
738 test_erase_nd<movable_and_copyable_int, 10>();
739
740 test_insert_nd<int, 10>(50);
741 test_insert_nd<value_nd, 10>(value_nd(50));
742 test_insert_nd<counting_value, 10>(counting_value(50));
743 BOOST_TEST(counting_value::count() == 0);
744 test_insert_nd<movable_and_copyable_int, 10>(produce_movable_and_copyable_int());
745
746 test_capacity_0_nd<int>();
747 test_capacity_0_nd<value_nd>();
748 test_capacity_0_nd<counting_value>();
749 BOOST_TEST(counting_value::count() == 0);
750 test_capacity_0_nd<movable_and_copyable_int>();
751
752 test_exceptions_nd<int, 10>();
753 test_exceptions_nd<value_nd, 10>();
754 test_exceptions_nd<counting_value, 10>();
755 BOOST_TEST(counting_value::count() == 0);
756 test_exceptions_nd<movable_and_copyable_int, 10>();
757
758 test_swap_and_move_nd<int, 10>();
759 test_swap_and_move_nd<value_nd, 10>();
760 test_swap_and_move_nd<counting_value, 10>();
761 BOOST_TEST(counting_value::count() == 0);
762 test_swap_and_move_nd<movable_and_copyable_int, 10>();
763
764 test_emplace_0p<counting_value, 10>();
765 BOOST_TEST(counting_value::count() == 0);
766
767 test_emplace_2p<counting_value, 10>();
768 BOOST_TEST(counting_value::count() == 0);
769
770 test_sv_elem<int, 10>(50);
771 test_sv_elem<value_nd, 10>(value_nd(50));
772 test_sv_elem<counting_value, 10>(counting_value(50));
773 BOOST_TEST(counting_value::count() == 0);
774 test_sv_elem<movable_and_copyable_int, 10>(movable_and_copyable_int(50));
775
776 BOOST_TEST(default_init_test() == true);
777
778 test_support_for_initializer_list();
779
780 ////////////////////////////////////
781 // Iterator testing
782 ////////////////////////////////////
783 {
784 typedef boost::container::static_vector<int, 3> cont_int;
785 cont_int a; a.push_back(0); a.push_back(1); a.push_back(2);
786 boost::intrusive::test::test_iterator_random< cont_int >(a);
787 }
788
789 return boost::report_errors();
790 }
791
792 /*
793
794 #include <boost/container/small_vector.hpp>
795 #include <type_traits>
796
797 struct S_trivial {
798 int i;
799 };
800 static_assert(std::is_nothrow_move_constructible<S_trivial>::value, "");
801 static_assert(std::is_nothrow_move_assignable<S_trivial>::value, "");
802
803 struct S1 {
804 int i = 0;
805 };
806 static_assert(std::is_nothrow_move_constructible<S1>::value, "");
807 static_assert(std::is_nothrow_move_assignable<S1>::value, "");
808
809 struct S2 {
810 int i = 0;
811 S2(S2&&) noexcept;
812 S2& operator=(S2&&) noexcept;
813 };
814 static_assert(std::is_nothrow_move_constructible<S2>::value, "");
815 static_assert(std::is_nothrow_move_assignable<S2>::value, "");
816
817 // Succeed
818 static_assert(std::is_nothrow_move_constructible<boost::container::small_vector<S_trivial, 1>>::value, "");
819 static_assert(std::is_nothrow_move_assignable<boost::container::small_vector<S_trivial, 1>>::value, "");
820
821 // Fail
822 static_assert(std::is_nothrow_move_constructible<boost::container::small_vector<S1, 1>>::value, "");
823 static_assert(std::is_nothrow_move_assignable<boost::container::small_vector<S1, 1>>::value, "");
824
825 // Fail
826 static_assert(std::is_nothrow_move_constructible<boost::container::small_vector<S2, 1>>::value, "");
827 static_assert(std::is_nothrow_move_assignable<boost::container::small_vector<S2, 1>>::value, "");
828
829 int main()
830 {
831 return 0;
832 }
833 */