]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/container/vector.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / container / vector.hpp
1 //////////////////////////////////////////////////////////////////////////////
2 //
3 // (C) Copyright Ion Gaztanaga 2005-2015. Distributed under the Boost
4 // Software License, Version 1.0. (See accompanying file
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 // See http://www.boost.org/libs/container for documentation.
8 //
9 //////////////////////////////////////////////////////////////////////////////
10
11 #ifndef BOOST_CONTAINER_CONTAINER_VECTOR_HPP
12 #define BOOST_CONTAINER_CONTAINER_VECTOR_HPP
13
14 #ifndef BOOST_CONFIG_HPP
15 # include <boost/config.hpp>
16 #endif
17
18 #if defined(BOOST_HAS_PRAGMA_ONCE)
19 # pragma once
20 #endif
21
22 #include <boost/container/detail/config_begin.hpp>
23 #include <boost/container/detail/workaround.hpp>
24
25 // container
26 #include <boost/container/container_fwd.hpp>
27 #include <boost/container/allocator_traits.hpp>
28 #include <boost/container/new_allocator.hpp> //new_allocator
29 #include <boost/container/throw_exception.hpp>
30 // container detail
31 #include <boost/container/detail/advanced_insert_int.hpp>
32 #include <boost/container/detail/algorithm.hpp> //equal()
33 #include <boost/container/detail/alloc_helpers.hpp>
34 #include <boost/container/detail/allocation_type.hpp>
35 #include <boost/container/detail/copy_move_algo.hpp>
36 #include <boost/container/detail/destroyers.hpp>
37 #include <boost/container/detail/iterator.hpp>
38 #include <boost/container/detail/iterators.hpp>
39 #include <boost/move/detail/iterator_to_raw_pointer.hpp>
40 #include <boost/container/detail/mpl.hpp>
41 #include <boost/container/detail/next_capacity.hpp>
42 #include <boost/move/detail/to_raw_pointer.hpp>
43 #include <boost/container/detail/type_traits.hpp>
44 #include <boost/container/detail/version_type.hpp>
45 // intrusive
46 #include <boost/intrusive/pointer_traits.hpp>
47 // move
48 #include <boost/move/adl_move_swap.hpp>
49 #include <boost/move/iterator.hpp>
50 #include <boost/move/traits.hpp>
51 #include <boost/move/utility_core.hpp>
52 // move/detail
53 #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
54 #include <boost/move/detail/fwd_macros.hpp>
55 #endif
56 #include <boost/move/detail/move_helpers.hpp>
57 // move/algo
58 #include <boost/move/algo/adaptive_merge.hpp>
59 #include <boost/move/algo/unique.hpp>
60 #include <boost/move/algo/predicate.hpp>
61 // other
62 #include <boost/core/no_exceptions_support.hpp>
63 #include <boost/assert.hpp>
64 #include <boost/cstdint.hpp>
65
66 //std
67 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
68 #include <initializer_list> //for std::initializer_list
69 #endif
70
71 namespace boost {
72 namespace container {
73
74 #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
75
76 namespace container_detail {
77
78 template <class Pointer, bool IsConst>
79 class vec_iterator
80 {
81 public:
82 typedef std::random_access_iterator_tag iterator_category;
83 typedef typename boost::intrusive::pointer_traits<Pointer>::element_type value_type;
84 typedef typename boost::intrusive::pointer_traits<Pointer>::difference_type difference_type;
85 typedef typename if_c
86 < IsConst
87 , typename boost::intrusive::pointer_traits<Pointer>::template
88 rebind_pointer<const value_type>::type
89 , Pointer
90 >::type pointer;
91 typedef typename boost::intrusive::pointer_traits<pointer> ptr_traits;
92 typedef typename ptr_traits::reference reference;
93
94 #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
95 private:
96 Pointer m_ptr;
97
98 public:
99 BOOST_CONTAINER_FORCEINLINE const Pointer &get_ptr() const BOOST_NOEXCEPT_OR_NOTHROW
100 { return m_ptr; }
101
102 BOOST_CONTAINER_FORCEINLINE Pointer &get_ptr() BOOST_NOEXCEPT_OR_NOTHROW
103 { return m_ptr; }
104
105 BOOST_CONTAINER_FORCEINLINE explicit vec_iterator(Pointer ptr) BOOST_NOEXCEPT_OR_NOTHROW
106 : m_ptr(ptr)
107 {}
108 #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
109
110 public:
111
112 //Constructors
113 BOOST_CONTAINER_FORCEINLINE vec_iterator() BOOST_NOEXCEPT_OR_NOTHROW
114 : m_ptr() //Value initialization to achieve "null iterators" (N3644)
115 {}
116
117 BOOST_CONTAINER_FORCEINLINE vec_iterator(vec_iterator<Pointer, false> const& other) BOOST_NOEXCEPT_OR_NOTHROW
118 : m_ptr(other.get_ptr())
119 {}
120
121 //Pointer like operators
122 BOOST_CONTAINER_FORCEINLINE reference operator*() const BOOST_NOEXCEPT_OR_NOTHROW
123 { return *m_ptr; }
124
125 BOOST_CONTAINER_FORCEINLINE pointer operator->() const BOOST_NOEXCEPT_OR_NOTHROW
126 { return ::boost::intrusive::pointer_traits<pointer>::pointer_to(this->operator*()); }
127
128 BOOST_CONTAINER_FORCEINLINE reference operator[](difference_type off) const BOOST_NOEXCEPT_OR_NOTHROW
129 { return m_ptr[off]; }
130
131 //Increment / Decrement
132 BOOST_CONTAINER_FORCEINLINE vec_iterator& operator++() BOOST_NOEXCEPT_OR_NOTHROW
133 { ++m_ptr; return *this; }
134
135 BOOST_CONTAINER_FORCEINLINE vec_iterator operator++(int) BOOST_NOEXCEPT_OR_NOTHROW
136 { return vec_iterator(m_ptr++); }
137
138 BOOST_CONTAINER_FORCEINLINE vec_iterator& operator--() BOOST_NOEXCEPT_OR_NOTHROW
139 { --m_ptr; return *this; }
140
141 BOOST_CONTAINER_FORCEINLINE vec_iterator operator--(int) BOOST_NOEXCEPT_OR_NOTHROW
142 { return vec_iterator(m_ptr--); }
143
144 //Arithmetic
145 BOOST_CONTAINER_FORCEINLINE vec_iterator& operator+=(difference_type off) BOOST_NOEXCEPT_OR_NOTHROW
146 { m_ptr += off; return *this; }
147
148 BOOST_CONTAINER_FORCEINLINE vec_iterator& operator-=(difference_type off) BOOST_NOEXCEPT_OR_NOTHROW
149 { m_ptr -= off; return *this; }
150
151 BOOST_CONTAINER_FORCEINLINE friend vec_iterator operator+(const vec_iterator &x, difference_type off) BOOST_NOEXCEPT_OR_NOTHROW
152 { return vec_iterator(x.m_ptr+off); }
153
154 BOOST_CONTAINER_FORCEINLINE friend vec_iterator operator+(difference_type off, vec_iterator right) BOOST_NOEXCEPT_OR_NOTHROW
155 { right.m_ptr += off; return right; }
156
157 BOOST_CONTAINER_FORCEINLINE friend vec_iterator operator-(vec_iterator left, difference_type off) BOOST_NOEXCEPT_OR_NOTHROW
158 { left.m_ptr -= off; return left; }
159
160 BOOST_CONTAINER_FORCEINLINE friend difference_type operator-(const vec_iterator &left, const vec_iterator& right) BOOST_NOEXCEPT_OR_NOTHROW
161 { return left.m_ptr - right.m_ptr; }
162
163 //Comparison operators
164 BOOST_CONTAINER_FORCEINLINE friend bool operator== (const vec_iterator& l, const vec_iterator& r) BOOST_NOEXCEPT_OR_NOTHROW
165 { return l.m_ptr == r.m_ptr; }
166
167 BOOST_CONTAINER_FORCEINLINE friend bool operator!= (const vec_iterator& l, const vec_iterator& r) BOOST_NOEXCEPT_OR_NOTHROW
168 { return l.m_ptr != r.m_ptr; }
169
170 BOOST_CONTAINER_FORCEINLINE friend bool operator< (const vec_iterator& l, const vec_iterator& r) BOOST_NOEXCEPT_OR_NOTHROW
171 { return l.m_ptr < r.m_ptr; }
172
173 BOOST_CONTAINER_FORCEINLINE friend bool operator<= (const vec_iterator& l, const vec_iterator& r) BOOST_NOEXCEPT_OR_NOTHROW
174 { return l.m_ptr <= r.m_ptr; }
175
176 BOOST_CONTAINER_FORCEINLINE friend bool operator> (const vec_iterator& l, const vec_iterator& r) BOOST_NOEXCEPT_OR_NOTHROW
177 { return l.m_ptr > r.m_ptr; }
178
179 BOOST_CONTAINER_FORCEINLINE friend bool operator>= (const vec_iterator& l, const vec_iterator& r) BOOST_NOEXCEPT_OR_NOTHROW
180 { return l.m_ptr >= r.m_ptr; }
181 };
182
183 template<class BiDirPosConstIt, class BiDirValueIt>
184 struct vector_insert_ordered_cursor
185 {
186 typedef typename iterator_traits<BiDirPosConstIt>::value_type size_type;
187 typedef typename iterator_traits<BiDirValueIt>::reference reference;
188
189 BOOST_CONTAINER_FORCEINLINE vector_insert_ordered_cursor(BiDirPosConstIt posit, BiDirValueIt valueit)
190 : last_position_it(posit), last_value_it(valueit)
191 {}
192
193 void operator --()
194 {
195 --last_value_it;
196 --last_position_it;
197 while(this->get_pos() == size_type(-1)){
198 --last_value_it;
199 --last_position_it;
200 }
201 }
202
203 BOOST_CONTAINER_FORCEINLINE size_type get_pos() const
204 { return *last_position_it; }
205
206 BOOST_CONTAINER_FORCEINLINE reference get_val()
207 { return *last_value_it; }
208
209 BiDirPosConstIt last_position_it;
210 BiDirValueIt last_value_it;
211 };
212
213 template<class T, class SizeType, class BiDirValueIt, class Comp>
214 struct vector_merge_cursor
215 {
216 typedef SizeType size_type;
217 typedef typename iterator_traits<BiDirValueIt>::reference reference;
218
219 BOOST_CONTAINER_FORCEINLINE vector_merge_cursor(T *pbeg, T *plast, BiDirValueIt valueit, Comp &cmp)
220 : m_pbeg(pbeg), m_pcur(--plast), m_valueit(valueit), m_cmp(cmp)
221 {}
222
223 void operator --()
224 {
225 --m_valueit;
226 const T &t = *m_valueit;
227 while((m_pcur + 1) != m_pbeg){
228 if(!m_cmp(t, *m_pcur)){
229 break;
230 }
231 --m_pcur;
232 }
233 }
234
235 BOOST_CONTAINER_FORCEINLINE size_type get_pos() const
236 { return static_cast<size_type>((m_pcur + 1) - m_pbeg); }
237
238 BOOST_CONTAINER_FORCEINLINE reference get_val()
239 { return *m_valueit; }
240
241 T *const m_pbeg;
242 T *m_pcur;
243 BiDirValueIt m_valueit;
244 Comp &m_cmp;
245 };
246
247 } //namespace container_detail {
248
249 template<class Pointer, bool IsConst>
250 BOOST_CONTAINER_FORCEINLINE const Pointer &vector_iterator_get_ptr(const container_detail::vec_iterator<Pointer, IsConst> &it) BOOST_NOEXCEPT_OR_NOTHROW
251 { return it.get_ptr(); }
252
253 template<class Pointer, bool IsConst>
254 BOOST_CONTAINER_FORCEINLINE Pointer &get_ptr(container_detail::vec_iterator<Pointer, IsConst> &it) BOOST_NOEXCEPT_OR_NOTHROW
255 { return it.get_ptr(); }
256
257 namespace container_detail {
258
259 struct uninitialized_size_t {};
260 static const uninitialized_size_t uninitialized_size = uninitialized_size_t();
261
262 template <class T>
263 struct vector_value_traits_base
264 {
265 static const bool trivial_dctr = is_trivially_destructible<T>::value;
266 static const bool trivial_dctr_after_move = has_trivial_destructor_after_move<T>::value;
267 static const bool trivial_copy = is_trivially_copy_constructible<T>::value;
268 static const bool nothrow_copy = is_nothrow_copy_constructible<T>::value || trivial_copy;
269 static const bool trivial_assign = is_trivially_copy_assignable<T>::value;
270 static const bool nothrow_assign = is_nothrow_copy_assignable<T>::value || trivial_assign;
271 };
272
273
274 template <class Allocator>
275 struct vector_value_traits
276 : public vector_value_traits_base<typename Allocator::value_type>
277 {
278 typedef vector_value_traits_base<typename Allocator::value_type> base_t;
279 //This is the anti-exception array destructor
280 //to deallocate values already constructed
281 typedef typename container_detail::if_c
282 <base_t::trivial_dctr
283 ,container_detail::null_scoped_destructor_n<Allocator>
284 ,container_detail::scoped_destructor_n<Allocator>
285 >::type ArrayDestructor;
286 //This is the anti-exception array deallocator
287 typedef container_detail::scoped_array_deallocator<Allocator> ArrayDeallocator;
288 };
289
290 //!This struct deallocates and allocated memory
291 template < class Allocator
292 , class AllocatorVersion = typename container_detail::version<Allocator>::type
293 >
294 struct vector_alloc_holder
295 : public Allocator
296 {
297 private:
298 BOOST_MOVABLE_BUT_NOT_COPYABLE(vector_alloc_holder)
299
300 public:
301 typedef Allocator allocator_type;
302 typedef boost::container::allocator_traits<Allocator> allocator_traits_type;
303 typedef typename allocator_traits_type::pointer pointer;
304 typedef typename allocator_traits_type::size_type size_type;
305 typedef typename allocator_traits_type::value_type value_type;
306
307 static bool is_propagable_from(const allocator_type &from_alloc, pointer p, const allocator_type &to_alloc, bool const propagate_allocator)
308 {
309 (void)propagate_allocator; (void)p; (void)to_alloc; (void)from_alloc;
310 const bool all_storage_propagable = !allocator_traits_type::is_partially_propagable::value ||
311 !allocator_traits_type::storage_is_unpropagable(from_alloc, p);
312 return all_storage_propagable && (propagate_allocator || allocator_traits_type::equal(from_alloc, to_alloc));
313 }
314
315 static bool are_swap_propagable(const allocator_type &l_a, pointer l_p, const allocator_type &r_a, pointer r_p, bool const propagate_allocator)
316 {
317 (void)propagate_allocator; (void)l_p; (void)r_p; (void)l_a; (void)r_a;
318 const bool all_storage_propagable = !allocator_traits_type::is_partially_propagable::value ||
319 !(allocator_traits_type::storage_is_unpropagable(l_a, l_p) || allocator_traits_type::storage_is_unpropagable(r_a, r_p));
320 return all_storage_propagable && (propagate_allocator || allocator_traits_type::equal(l_a, r_a));
321 }
322
323 //Constructor, does not throw
324 vector_alloc_holder()
325 BOOST_NOEXCEPT_IF(container_detail::is_nothrow_default_constructible<Allocator>::value)
326 : Allocator(), m_start(), m_size(), m_capacity()
327 {}
328
329 //Constructor, does not throw
330 template<class AllocConvertible>
331 explicit vector_alloc_holder(BOOST_FWD_REF(AllocConvertible) a) BOOST_NOEXCEPT_OR_NOTHROW
332 : Allocator(boost::forward<AllocConvertible>(a)), m_start(), m_size(), m_capacity()
333 {}
334
335 //Constructor, does not throw
336 template<class AllocConvertible>
337 vector_alloc_holder(uninitialized_size_t, BOOST_FWD_REF(AllocConvertible) a, size_type initial_size)
338 : Allocator(boost::forward<AllocConvertible>(a))
339 , m_start()
340 , m_size(initial_size) //Size is initialized here so vector should only call uninitialized_xxx after this
341 , m_capacity()
342 {
343 if(initial_size){
344 pointer reuse = pointer();
345 m_start = this->allocation_command(allocate_new, initial_size, m_capacity = initial_size, reuse);
346 }
347 }
348
349 //Constructor, does not throw
350 vector_alloc_holder(uninitialized_size_t, size_type initial_size)
351 : Allocator()
352 , m_start()
353 , m_size(initial_size) //Size is initialized here so vector should only call uninitialized_xxx after this
354 , m_capacity()
355 {
356 if(initial_size){
357 pointer reuse = pointer();
358 m_start = this->allocation_command(allocate_new, initial_size, m_capacity = initial_size, reuse);
359 }
360 }
361
362 vector_alloc_holder(BOOST_RV_REF(vector_alloc_holder) holder) BOOST_NOEXCEPT_OR_NOTHROW
363 : Allocator(BOOST_MOVE_BASE(Allocator, holder))
364 , m_start(holder.m_start)
365 , m_size(holder.m_size)
366 , m_capacity(holder.m_capacity)
367 {
368 holder.m_start = pointer();
369 holder.m_size = holder.m_capacity = 0;
370 }
371
372 vector_alloc_holder(pointer p, size_type capacity, BOOST_RV_REF(vector_alloc_holder) holder)
373 : Allocator(BOOST_MOVE_BASE(Allocator, holder))
374 , m_start(p)
375 , m_size(holder.m_size)
376 , m_capacity(capacity)
377 {
378 allocator_type &this_alloc = this->alloc();
379 allocator_type &x_alloc = holder.alloc();
380 if(this->is_propagable_from(x_alloc, holder.start(), this_alloc, true)){
381 if(this->m_capacity){
382 allocator_traits_type::deallocate(this->alloc(), this->m_start, this->m_capacity);
383 }
384 m_start = holder.m_start;
385 m_capacity = holder.m_capacity;
386 holder.m_start = pointer();
387 holder.m_capacity = holder.m_size = 0;
388 }
389 else if(this->m_capacity < holder.m_size){
390 size_type const n = holder.m_size;
391 pointer reuse = pointer();
392 m_start = this->allocation_command(allocate_new, n, m_capacity = n, reuse);
393 #ifdef BOOST_CONTAINER_VECTOR_ALLOC_STATS
394 this->num_alloc += n != 0;
395 #endif
396 }
397 }
398
399 vector_alloc_holder(pointer p, size_type n)
400 BOOST_NOEXCEPT_IF(container_detail::is_nothrow_default_constructible<Allocator>::value)
401 : Allocator()
402 , m_start(p)
403 , m_size()
404 , m_capacity(n)
405 {}
406
407 template<class AllocFwd>
408 vector_alloc_holder(pointer p, size_type n, BOOST_FWD_REF(AllocFwd) a)
409 : Allocator(::boost::forward<AllocFwd>(a))
410 , m_start(p)
411 , m_size()
412 , m_capacity(n)
413 {}
414
415 BOOST_CONTAINER_FORCEINLINE ~vector_alloc_holder() BOOST_NOEXCEPT_OR_NOTHROW
416 {
417 if(this->m_capacity){
418 allocator_traits_type::deallocate(this->alloc(), this->m_start, this->m_capacity);
419 }
420 }
421
422 BOOST_CONTAINER_FORCEINLINE pointer allocation_command(boost::container::allocation_type command,
423 size_type limit_size, size_type &prefer_in_recvd_out_size, pointer &reuse)
424 {
425 typedef typename container_detail::version<Allocator>::type alloc_version;
426 return this->priv_allocation_command(alloc_version(), command, limit_size, prefer_in_recvd_out_size, reuse);
427 }
428
429 bool try_expand_fwd(size_type at_least)
430 {
431 //There is not enough memory, try to expand the old one
432 const size_type new_cap = this->capacity() + at_least;
433 size_type real_cap = new_cap;
434 pointer reuse = this->start();
435 bool const success = !!this->allocation_command(expand_fwd, new_cap, real_cap, reuse);
436 //Check for forward expansion
437 if(success){
438 #ifdef BOOST_CONTAINER_VECTOR_ALLOC_STATS
439 ++this->num_expand_fwd;
440 #endif
441 this->capacity(real_cap);
442 }
443 return success;
444 }
445
446 BOOST_CONTAINER_FORCEINLINE size_type next_capacity(size_type additional_objects) const
447 {
448 return next_capacity_calculator
449 <size_type, NextCapacityDouble //NextCapacity60Percent
450 >::get( allocator_traits_type::max_size(this->alloc())
451 , this->m_capacity, additional_objects );
452 }
453
454 pointer m_start;
455 size_type m_size;
456 size_type m_capacity;
457
458 void swap_resources(vector_alloc_holder &x) BOOST_NOEXCEPT_OR_NOTHROW
459 {
460 boost::adl_move_swap(this->m_start, x.m_start);
461 boost::adl_move_swap(this->m_size, x.m_size);
462 boost::adl_move_swap(this->m_capacity, x.m_capacity);
463 }
464
465 void steal_resources(vector_alloc_holder &x) BOOST_NOEXCEPT_OR_NOTHROW
466 {
467 this->m_start = x.m_start;
468 this->m_size = x.m_size;
469 this->m_capacity = x.m_capacity;
470 x.m_start = pointer();
471 x.m_size = x.m_capacity = 0;
472 }
473
474 BOOST_CONTAINER_FORCEINLINE Allocator &alloc() BOOST_NOEXCEPT_OR_NOTHROW
475 { return *this; }
476
477 BOOST_CONTAINER_FORCEINLINE const Allocator &alloc() const BOOST_NOEXCEPT_OR_NOTHROW
478 { return *this; }
479
480 const pointer &start() const BOOST_NOEXCEPT_OR_NOTHROW { return m_start; }
481 const size_type &capacity() const BOOST_NOEXCEPT_OR_NOTHROW { return m_capacity; }
482 void start(const pointer &p) BOOST_NOEXCEPT_OR_NOTHROW { m_start = p; }
483 void capacity(const size_type &c) BOOST_NOEXCEPT_OR_NOTHROW { m_capacity = c; }
484
485 private:
486 void priv_first_allocation(size_type cap)
487 {
488 if(cap){
489 pointer reuse = pointer();
490 m_start = this->allocation_command(allocate_new, cap, cap, reuse);
491 m_capacity = cap;
492 #ifdef BOOST_CONTAINER_VECTOR_ALLOC_STATS
493 ++this->num_alloc;
494 #endif
495 }
496 }
497
498 BOOST_CONTAINER_FORCEINLINE pointer priv_allocation_command(version_1, boost::container::allocation_type command,
499 size_type ,
500 size_type &prefer_in_recvd_out_size,
501 pointer &reuse)
502 {
503 (void)command;
504 BOOST_ASSERT( (command & allocate_new));
505 BOOST_ASSERT(!(command & nothrow_allocation));
506 pointer const p = allocator_traits_type::allocate(this->alloc(), prefer_in_recvd_out_size, reuse);
507 reuse = pointer();
508 return p;
509 }
510
511 pointer priv_allocation_command(version_2, boost::container::allocation_type command,
512 size_type limit_size,
513 size_type &prefer_in_recvd_out_size,
514 pointer &reuse)
515 {
516 return this->alloc().allocation_command(command, limit_size, prefer_in_recvd_out_size, reuse);
517 }
518 };
519
520 //!This struct deallocates and allocated memory
521 template <class Allocator>
522 struct vector_alloc_holder<Allocator, version_0>
523 : public Allocator
524 {
525 private:
526 BOOST_MOVABLE_BUT_NOT_COPYABLE(vector_alloc_holder)
527
528 public:
529 typedef boost::container::allocator_traits<Allocator> allocator_traits_type;
530 typedef typename allocator_traits_type::pointer pointer;
531 typedef typename allocator_traits_type::size_type size_type;
532 typedef typename allocator_traits_type::value_type value_type;
533
534 template <class OtherAllocator, class OtherAllocatorVersion>
535 friend struct vector_alloc_holder;
536
537 //Constructor, does not throw
538 vector_alloc_holder()
539 BOOST_NOEXCEPT_IF(container_detail::is_nothrow_default_constructible<Allocator>::value)
540 : Allocator(), m_size()
541 {}
542
543 //Constructor, does not throw
544 template<class AllocConvertible>
545 explicit vector_alloc_holder(BOOST_FWD_REF(AllocConvertible) a) BOOST_NOEXCEPT_OR_NOTHROW
546 : Allocator(boost::forward<AllocConvertible>(a)), m_size()
547 {}
548
549 //Constructor, does not throw
550 template<class AllocConvertible>
551 vector_alloc_holder(uninitialized_size_t, BOOST_FWD_REF(AllocConvertible) a, size_type initial_size)
552 : Allocator(boost::forward<AllocConvertible>(a))
553 , m_size(initial_size) //Size is initialized here...
554 {
555 //... and capacity here, so vector, must call uninitialized_xxx in the derived constructor
556 this->priv_first_allocation(initial_size);
557 }
558
559 //Constructor, does not throw
560 vector_alloc_holder(uninitialized_size_t, size_type initial_size)
561 : Allocator()
562 , m_size(initial_size) //Size is initialized here...
563 {
564 //... and capacity here, so vector, must call uninitialized_xxx in the derived constructor
565 this->priv_first_allocation(initial_size);
566 }
567
568 vector_alloc_holder(BOOST_RV_REF(vector_alloc_holder) holder)
569 : Allocator(BOOST_MOVE_BASE(Allocator, holder))
570 , m_size(holder.m_size) //Size is initialized here so vector should only call uninitialized_xxx after this
571 {
572 ::boost::container::uninitialized_move_alloc_n
573 (this->alloc(), boost::movelib::to_raw_pointer(holder.start()), m_size, boost::movelib::to_raw_pointer(this->start()));
574 }
575
576 template<class OtherAllocator, class OtherAllocatorVersion>
577 vector_alloc_holder(BOOST_RV_REF_BEG vector_alloc_holder<OtherAllocator, OtherAllocatorVersion> BOOST_RV_REF_END holder)
578 : Allocator()
579 , m_size(holder.m_size) //Initialize it to m_size as first_allocation can only succeed or abort
580 {
581 //Different allocator type so we must check we have enough storage
582 const size_type n = holder.m_size;
583 this->priv_first_allocation(n);
584 ::boost::container::uninitialized_move_alloc_n
585 (this->alloc(), boost::movelib::to_raw_pointer(holder.start()), n, boost::movelib::to_raw_pointer(this->start()));
586 }
587
588 BOOST_CONTAINER_FORCEINLINE void priv_first_allocation(size_type cap)
589 {
590 if(cap > Allocator::internal_capacity){
591 throw_bad_alloc();
592 }
593 }
594
595 BOOST_CONTAINER_FORCEINLINE void deep_swap(vector_alloc_holder &x)
596 {
597 this->priv_deep_swap(x);
598 }
599
600 template<class OtherAllocator, class OtherAllocatorVersion>
601 void deep_swap(vector_alloc_holder<OtherAllocator, OtherAllocatorVersion> &x)
602 {
603 if(this->m_size > OtherAllocator::internal_capacity || x.m_size > Allocator::internal_capacity){
604 throw_bad_alloc();
605 }
606 this->priv_deep_swap(x);
607 }
608
609 BOOST_CONTAINER_FORCEINLINE void swap_resources(vector_alloc_holder &) BOOST_NOEXCEPT_OR_NOTHROW
610 { //Containers with version 0 allocators can't be moved without moving elements one by one
611 throw_bad_alloc();
612 }
613
614
615 BOOST_CONTAINER_FORCEINLINE void steal_resources(vector_alloc_holder &)
616 { //Containers with version 0 allocators can't be moved without moving elements one by one
617 throw_bad_alloc();
618 }
619
620 BOOST_CONTAINER_FORCEINLINE Allocator &alloc() BOOST_NOEXCEPT_OR_NOTHROW
621 { return *this; }
622
623 BOOST_CONTAINER_FORCEINLINE const Allocator &alloc() const BOOST_NOEXCEPT_OR_NOTHROW
624 { return *this; }
625
626 BOOST_CONTAINER_FORCEINLINE bool try_expand_fwd(size_type at_least)
627 { return !at_least; }
628
629 BOOST_CONTAINER_FORCEINLINE pointer start() const BOOST_NOEXCEPT_OR_NOTHROW { return Allocator::internal_storage(); }
630 BOOST_CONTAINER_FORCEINLINE size_type capacity() const BOOST_NOEXCEPT_OR_NOTHROW { return Allocator::internal_capacity; }
631 size_type m_size;
632
633 private:
634
635 template<class OtherAllocator, class OtherAllocatorVersion>
636 void priv_deep_swap(vector_alloc_holder<OtherAllocator, OtherAllocatorVersion> &x)
637 {
638 const size_type MaxTmpStorage = sizeof(value_type)*Allocator::internal_capacity;
639 value_type *const first_this = boost::movelib::to_raw_pointer(this->start());
640 value_type *const first_x = boost::movelib::to_raw_pointer(x.start());
641
642 if(this->m_size < x.m_size){
643 boost::container::deep_swap_alloc_n<MaxTmpStorage>(this->alloc(), first_this, this->m_size, first_x, x.m_size);
644 }
645 else{
646 boost::container::deep_swap_alloc_n<MaxTmpStorage>(this->alloc(), first_x, x.m_size, first_this, this->m_size);
647 }
648 boost::adl_move_swap(this->m_size, x.m_size);
649 }
650 };
651
652 } //namespace container_detail {
653
654 #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
655
656 //! A vector is a sequence that supports random access to elements, constant
657 //! time insertion and removal of elements at the end, and linear time insertion
658 //! and removal of elements at the beginning or in the middle. The number of
659 //! elements in a vector may vary dynamically; memory management is automatic.
660 //!
661 //! \tparam T The type of object that is stored in the vector
662 //! \tparam Allocator The allocator used for all internal memory management
663 template <class T, class Allocator BOOST_CONTAINER_DOCONLY(= new_allocator<T>) >
664 class vector
665 {
666 #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
667
668 struct value_less
669 {
670 typedef typename boost::container::allocator_traits<Allocator>::value_type value_type;
671 bool operator()(const value_type &a, const value_type &b) const
672 { return a < b; }
673 };
674
675 typedef typename container_detail::version<Allocator>::type alloc_version;
676 typedef boost::container::container_detail::vector_alloc_holder<Allocator> alloc_holder_t;
677 alloc_holder_t m_holder;
678 typedef allocator_traits<Allocator> allocator_traits_type;
679 template <class U, class UAllocator>
680 friend class vector;
681
682 typedef typename allocator_traits_type::pointer pointer_impl;
683 typedef container_detail::vec_iterator<pointer_impl, false> iterator_impl;
684 typedef container_detail::vec_iterator<pointer_impl, true > const_iterator_impl;
685
686 protected:
687 static bool is_propagable_from(const Allocator &from_alloc, pointer_impl p, const Allocator &to_alloc, bool const propagate_allocator)
688 { return alloc_holder_t::is_propagable_from(from_alloc, p, to_alloc, propagate_allocator); }
689
690 static bool are_swap_propagable( const Allocator &l_a, pointer_impl l_p
691 , const Allocator &r_a, pointer_impl r_p, bool const propagate_allocator)
692 { return alloc_holder_t::are_swap_propagable(l_a, l_p, r_a, r_p, propagate_allocator); }
693
694 #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
695 public:
696 //////////////////////////////////////////////
697 //
698 // types
699 //
700 //////////////////////////////////////////////
701
702 typedef T value_type;
703 typedef typename ::boost::container::allocator_traits<Allocator>::pointer pointer;
704 typedef typename ::boost::container::allocator_traits<Allocator>::const_pointer const_pointer;
705 typedef typename ::boost::container::allocator_traits<Allocator>::reference reference;
706 typedef typename ::boost::container::allocator_traits<Allocator>::const_reference const_reference;
707 typedef typename ::boost::container::allocator_traits<Allocator>::size_type size_type;
708 typedef typename ::boost::container::allocator_traits<Allocator>::difference_type difference_type;
709 typedef Allocator allocator_type;
710 typedef Allocator stored_allocator_type;
711 typedef BOOST_CONTAINER_IMPDEF(iterator_impl) iterator;
712 typedef BOOST_CONTAINER_IMPDEF(const_iterator_impl) const_iterator;
713 typedef BOOST_CONTAINER_IMPDEF(boost::container::reverse_iterator<iterator>) reverse_iterator;
714 typedef BOOST_CONTAINER_IMPDEF(boost::container::reverse_iterator<const_iterator>) const_reverse_iterator;
715
716 #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
717 private:
718 BOOST_COPYABLE_AND_MOVABLE(vector)
719 typedef container_detail::vector_value_traits<Allocator> value_traits;
720 typedef constant_iterator<T, difference_type> cvalue_iterator;
721
722 protected:
723
724 BOOST_CONTAINER_FORCEINLINE void steal_resources(vector &x)
725 { return this->m_holder.steal_resources(x.m_holder); }
726
727 struct initial_capacity_t{};
728 template<class AllocFwd>
729 BOOST_CONTAINER_FORCEINLINE vector(initial_capacity_t, pointer initial_memory, size_type capacity, BOOST_FWD_REF(AllocFwd) a)
730 : m_holder(initial_memory, capacity, ::boost::forward<AllocFwd>(a))
731 {}
732
733 BOOST_CONTAINER_FORCEINLINE vector(initial_capacity_t, pointer initial_memory, size_type capacity)
734 : m_holder(initial_memory, capacity)
735 {}
736
737 #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
738
739 public:
740 //////////////////////////////////////////////
741 //
742 // construct/copy/destroy
743 //
744 //////////////////////////////////////////////
745
746 //! <b>Effects</b>: Constructs a vector taking the allocator as parameter.
747 //!
748 //! <b>Throws</b>: Nothing.
749 //!
750 //! <b>Complexity</b>: Constant.
751 vector() BOOST_NOEXCEPT_IF(container_detail::is_nothrow_default_constructible<Allocator>::value)
752 : m_holder()
753 {}
754
755 //! <b>Effects</b>: Constructs a vector taking the allocator as parameter.
756 //!
757 //! <b>Throws</b>: Nothing
758 //!
759 //! <b>Complexity</b>: Constant.
760 explicit vector(const allocator_type& a) BOOST_NOEXCEPT_OR_NOTHROW
761 : m_holder(a)
762 {}
763
764 //! <b>Effects</b>: Constructs a vector and inserts n value initialized values.
765 //!
766 //! <b>Throws</b>: If allocator_type's allocation
767 //! throws or T's value initialization throws.
768 //!
769 //! <b>Complexity</b>: Linear to n.
770 explicit vector(size_type n)
771 : m_holder(container_detail::uninitialized_size, n)
772 {
773 #ifdef BOOST_CONTAINER_VECTOR_ALLOC_STATS
774 this->num_alloc += n != 0;
775 #endif
776 boost::container::uninitialized_value_init_alloc_n
777 (this->m_holder.alloc(), n, this->priv_raw_begin());
778 }
779
780 //! <b>Effects</b>: Constructs a vector that will use a copy of allocator a
781 //! and inserts n value initialized values.
782 //!
783 //! <b>Throws</b>: If allocator_type's allocation
784 //! throws or T's value initialization throws.
785 //!
786 //! <b>Complexity</b>: Linear to n.
787 explicit vector(size_type n, const allocator_type &a)
788 : m_holder(container_detail::uninitialized_size, a, n)
789 {
790 #ifdef BOOST_CONTAINER_VECTOR_ALLOC_STATS
791 this->num_alloc += n != 0;
792 #endif
793 boost::container::uninitialized_value_init_alloc_n
794 (this->m_holder.alloc(), n, this->priv_raw_begin());
795 }
796
797 //! <b>Effects</b>: Constructs a vector that will use a copy of allocator a
798 //! and inserts n default initialized values.
799 //!
800 //! <b>Throws</b>: If allocator_type's allocation
801 //! throws or T's default initialization throws.
802 //!
803 //! <b>Complexity</b>: Linear to n.
804 //!
805 //! <b>Note</b>: Non-standard extension
806 vector(size_type n, default_init_t)
807 : m_holder(container_detail::uninitialized_size, n)
808 {
809 #ifdef BOOST_CONTAINER_VECTOR_ALLOC_STATS
810 this->num_alloc += n != 0;
811 #endif
812 boost::container::uninitialized_default_init_alloc_n
813 (this->m_holder.alloc(), n, this->priv_raw_begin());
814 }
815
816 //! <b>Effects</b>: Constructs a vector that will use a copy of allocator a
817 //! and inserts n default initialized values.
818 //!
819 //! <b>Throws</b>: If allocator_type's allocation
820 //! throws or T's default initialization throws.
821 //!
822 //! <b>Complexity</b>: Linear to n.
823 //!
824 //! <b>Note</b>: Non-standard extension
825 vector(size_type n, default_init_t, const allocator_type &a)
826 : m_holder(container_detail::uninitialized_size, a, n)
827 {
828 #ifdef BOOST_CONTAINER_VECTOR_ALLOC_STATS
829 this->num_alloc += n != 0;
830 #endif
831 boost::container::uninitialized_default_init_alloc_n
832 (this->m_holder.alloc(), n, this->priv_raw_begin());
833 }
834
835 //! <b>Effects</b>: Constructs a vector
836 //! and inserts n copies of value.
837 //!
838 //! <b>Throws</b>: If allocator_type's allocation
839 //! throws or T's copy constructor throws.
840 //!
841 //! <b>Complexity</b>: Linear to n.
842 vector(size_type n, const T& value)
843 : m_holder(container_detail::uninitialized_size, n)
844 {
845 #ifdef BOOST_CONTAINER_VECTOR_ALLOC_STATS
846 this->num_alloc += n != 0;
847 #endif
848 boost::container::uninitialized_fill_alloc_n
849 (this->m_holder.alloc(), value, n, this->priv_raw_begin());
850 }
851
852 //! <b>Effects</b>: Constructs a vector that will use a copy of allocator a
853 //! and inserts n copies of value.
854 //!
855 //! <b>Throws</b>: If allocation
856 //! throws or T's copy constructor throws.
857 //!
858 //! <b>Complexity</b>: Linear to n.
859 vector(size_type n, const T& value, const allocator_type& a)
860 : m_holder(container_detail::uninitialized_size, a, n)
861 {
862 #ifdef BOOST_CONTAINER_VECTOR_ALLOC_STATS
863 this->num_alloc += n != 0;
864 #endif
865 boost::container::uninitialized_fill_alloc_n
866 (this->m_holder.alloc(), value, n, this->priv_raw_begin());
867 }
868
869 //! <b>Effects</b>: Constructs a vector
870 //! and inserts a copy of the range [first, last) in the vector.
871 //!
872 //! <b>Throws</b>: If allocator_type's allocation
873 //! throws or T's constructor taking a dereferenced InIt throws.
874 //!
875 //! <b>Complexity</b>: Linear to the range [first, last).
876 template <class InIt>
877 vector(InIt first, InIt last
878 BOOST_CONTAINER_DOCIGN(BOOST_MOVE_I typename container_detail::disable_if_c
879 < container_detail::is_convertible<InIt BOOST_MOVE_I size_type>::value
880 BOOST_MOVE_I container_detail::nat >::type * = 0)
881 )
882 : m_holder()
883 { this->assign(first, last); }
884
885 //! <b>Effects</b>: Constructs a vector that will use a copy of allocator a
886 //! and inserts a copy of the range [first, last) in the vector.
887 //!
888 //! <b>Throws</b>: If allocator_type's allocation
889 //! throws or T's constructor taking a dereferenced InIt throws.
890 //!
891 //! <b>Complexity</b>: Linear to the range [first, last).
892 template <class InIt>
893 vector(InIt first, InIt last, const allocator_type& a
894 BOOST_CONTAINER_DOCIGN(BOOST_MOVE_I typename container_detail::disable_if_c
895 < container_detail::is_convertible<InIt BOOST_MOVE_I size_type>::value
896 BOOST_MOVE_I container_detail::nat >::type * = 0)
897 )
898 : m_holder(a)
899 { this->assign(first, last); }
900
901 //! <b>Effects</b>: Copy constructs a vector.
902 //!
903 //! <b>Postcondition</b>: x == *this.
904 //!
905 //! <b>Throws</b>: If allocator_type's allocation
906 //! throws or T's copy constructor throws.
907 //!
908 //! <b>Complexity</b>: Linear to the elements x contains.
909 vector(const vector &x)
910 : m_holder( container_detail::uninitialized_size
911 , allocator_traits_type::select_on_container_copy_construction(x.m_holder.alloc())
912 , x.size())
913 {
914 #ifdef BOOST_CONTAINER_VECTOR_ALLOC_STATS
915 this->num_alloc += x.size() != 0;
916 #endif
917 ::boost::container::uninitialized_copy_alloc_n
918 ( this->m_holder.alloc(), x.priv_raw_begin()
919 , x.size(), this->priv_raw_begin());
920 }
921
922 //! <b>Effects</b>: Move constructor. Moves x's resources to *this.
923 //!
924 //! <b>Throws</b>: Nothing
925 //!
926 //! <b>Complexity</b>: Constant.
927 vector(BOOST_RV_REF(vector) x) BOOST_NOEXCEPT_OR_NOTHROW
928 : m_holder(boost::move(x.m_holder))
929 { BOOST_STATIC_ASSERT((!allocator_traits_type::is_partially_propagable::value)); }
930
931 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
932 //! <b>Effects</b>: Constructs a vector that will use a copy of allocator a
933 //! and inserts a copy of the range [il.begin(), il.last()) in the vector
934 //!
935 //! <b>Throws</b>: If T's constructor taking a dereferenced initializer_list iterator throws.
936 //!
937 //! <b>Complexity</b>: Linear to the range [il.begin(), il.end()).
938 vector(std::initializer_list<value_type> il, const allocator_type& a = allocator_type())
939 : m_holder(a)
940 {
941 this->assign(il.begin(), il.end());
942 }
943 #endif
944
945 #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
946
947 //! <b>Effects</b>: Move constructor. Moves x's resources to *this.
948 //!
949 //! <b>Throws</b>: If T's move constructor or allocation throws
950 //!
951 //! <b>Complexity</b>: Linear.
952 //!
953 //! <b>Note</b>: Non-standard extension to support static_vector
954 template<class OtherAllocator>
955 vector(BOOST_RV_REF_BEG vector<T, OtherAllocator> BOOST_RV_REF_END x
956 , typename container_detail::enable_if_c
957 < container_detail::is_version<OtherAllocator, 0>::value>::type * = 0
958 )
959 : m_holder(boost::move(x.m_holder))
960 {}
961
962 #endif //!defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
963
964 //! <b>Effects</b>: Copy constructs a vector using the specified allocator.
965 //!
966 //! <b>Postcondition</b>: x == *this.
967 //!
968 //! <b>Throws</b>: If allocation
969 //! throws or T's copy constructor throws.
970 //!
971 //! <b>Complexity</b>: Linear to the elements x contains.
972 vector(const vector &x, const allocator_type &a)
973 : m_holder(container_detail::uninitialized_size, a, x.size())
974 {
975 #ifdef BOOST_CONTAINER_VECTOR_ALLOC_STATS
976 this->num_alloc += x.size() != 0;
977 #endif
978 ::boost::container::uninitialized_copy_alloc_n_source
979 ( this->m_holder.alloc(), x.priv_raw_begin()
980 , x.size(), this->priv_raw_begin());
981 }
982
983 //! <b>Effects</b>: Move constructor using the specified allocator.
984 //! Moves x's resources to *this if a == allocator_type().
985 //! Otherwise copies values from x to *this.
986 //!
987 //! <b>Throws</b>: If allocation or T's copy constructor throws.
988 //!
989 //! <b>Complexity</b>: Constant if a == x.get_allocator(), linear otherwise.
990 vector(BOOST_RV_REF(vector) x, const allocator_type &a)
991 : m_holder( container_detail::uninitialized_size, a
992 , is_propagable_from(x.get_stored_allocator(), x.m_holder.start(), a, true) ? 0 : x.size()
993 )
994 {
995 if(is_propagable_from(x.get_stored_allocator(), x.m_holder.start(), a, true)){
996 this->m_holder.steal_resources(x.m_holder);
997 }
998 else{
999 const size_type n = x.size();
1000 #ifdef BOOST_CONTAINER_VECTOR_ALLOC_STATS
1001 this->num_alloc += n != 0;
1002 #endif
1003 ::boost::container::uninitialized_move_alloc_n_source
1004 ( this->m_holder.alloc(), x.priv_raw_begin()
1005 , n, this->priv_raw_begin());
1006 }
1007 }
1008
1009 //! <b>Effects</b>: Destroys the vector. All stored values are destroyed
1010 //! and used memory is deallocated.
1011 //!
1012 //! <b>Throws</b>: Nothing.
1013 //!
1014 //! <b>Complexity</b>: Linear to the number of elements.
1015 ~vector() BOOST_NOEXCEPT_OR_NOTHROW
1016 {
1017 boost::container::destroy_alloc_n
1018 (this->get_stored_allocator(), this->priv_raw_begin(), this->m_holder.m_size);
1019 //vector_alloc_holder deallocates the data
1020 }
1021
1022 //! <b>Effects</b>: Makes *this contain the same elements as x.
1023 //!
1024 //! <b>Postcondition</b>: this->size() == x.size(). *this contains a copy
1025 //! of each of x's elements.
1026 //!
1027 //! <b>Throws</b>: If memory allocation throws or T's copy/move constructor/assignment throws.
1028 //!
1029 //! <b>Complexity</b>: Linear to the number of elements in x.
1030 BOOST_CONTAINER_FORCEINLINE vector& operator=(BOOST_COPY_ASSIGN_REF(vector) x)
1031 {
1032 if (&x != this){
1033 this->priv_copy_assign(x);
1034 }
1035 return *this;
1036 }
1037
1038 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
1039 //! <b>Effects</b>: Make *this container contains elements from il.
1040 //!
1041 //! <b>Complexity</b>: Linear to the range [il.begin(), il.end()).
1042 BOOST_CONTAINER_FORCEINLINE vector& operator=(std::initializer_list<value_type> il)
1043 {
1044 this->assign(il.begin(), il.end());
1045 return *this;
1046 }
1047 #endif
1048
1049 //! <b>Effects</b>: Move assignment. All x's values are transferred to *this.
1050 //!
1051 //! <b>Postcondition</b>: x.empty(). *this contains a the elements x had
1052 //! before the function.
1053 //!
1054 //! <b>Throws</b>: If allocator_traits_type::propagate_on_container_move_assignment
1055 //! is false and (allocation throws or value_type's move constructor throws)
1056 //!
1057 //! <b>Complexity</b>: Constant if allocator_traits_type::
1058 //! propagate_on_container_move_assignment is true or
1059 //! this->get>allocator() == x.get_allocator(). Linear otherwise.
1060 BOOST_CONTAINER_FORCEINLINE vector& operator=(BOOST_RV_REF(vector) x)
1061 BOOST_NOEXCEPT_IF(allocator_traits_type::propagate_on_container_move_assignment::value
1062 || allocator_traits_type::is_always_equal::value)
1063 {
1064 BOOST_ASSERT(&x != this);
1065 this->priv_move_assign(boost::move(x));
1066 return *this;
1067 }
1068
1069 #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
1070
1071 //! <b>Effects</b>: Move assignment. All x's values are transferred to *this.
1072 //!
1073 //! <b>Postcondition</b>: x.empty(). *this contains a the elements x had
1074 //! before the function.
1075 //!
1076 //! <b>Throws</b>: If move constructor/assignment of T throws or allocation throws
1077 //!
1078 //! <b>Complexity</b>: Linear.
1079 //!
1080 //! <b>Note</b>: Non-standard extension to support static_vector
1081 template<class OtherAllocator>
1082 BOOST_CONTAINER_FORCEINLINE typename container_detail::enable_if_and
1083 < vector&
1084 , container_detail::is_version<OtherAllocator, 0>
1085 , container_detail::is_different<OtherAllocator, allocator_type>
1086 >::type
1087 operator=(BOOST_RV_REF_BEG vector<value_type, OtherAllocator> BOOST_RV_REF_END x)
1088 {
1089 this->priv_move_assign(boost::move(x));
1090 return *this;
1091 }
1092
1093 //! <b>Effects</b>: Copy assignment. All x's values are copied to *this.
1094 //!
1095 //! <b>Postcondition</b>: x.empty(). *this contains a the elements x had
1096 //! before the function.
1097 //!
1098 //! <b>Throws</b>: If move constructor/assignment of T throws or allocation throws
1099 //!
1100 //! <b>Complexity</b>: Linear.
1101 //!
1102 //! <b>Note</b>: Non-standard extension to support static_vector
1103 template<class OtherAllocator>
1104 BOOST_CONTAINER_FORCEINLINE typename container_detail::enable_if_and
1105 < vector&
1106 , container_detail::is_version<OtherAllocator, 0>
1107 , container_detail::is_different<OtherAllocator, allocator_type>
1108 >::type
1109 operator=(const vector<value_type, OtherAllocator> &x)
1110 {
1111 this->priv_copy_assign(x);
1112 return *this;
1113 }
1114
1115 #endif
1116
1117 //! <b>Effects</b>: Assigns the the range [first, last) to *this.
1118 //!
1119 //! <b>Throws</b>: If memory allocation throws or T's copy/move constructor/assignment or
1120 //! T's constructor/assignment from dereferencing InpIt throws.
1121 //!
1122 //! <b>Complexity</b>: Linear to n.
1123 template <class InIt>
1124 void assign(InIt first, InIt last
1125 BOOST_CONTAINER_DOCIGN(BOOST_MOVE_I typename container_detail::disable_if_or
1126 < void
1127 BOOST_MOVE_I container_detail::is_convertible<InIt BOOST_MOVE_I size_type>
1128 BOOST_MOVE_I container_detail::and_
1129 < container_detail::is_different<alloc_version BOOST_MOVE_I version_0>
1130 BOOST_MOVE_I container_detail::is_not_input_iterator<InIt>
1131 >
1132 >::type * = 0)
1133 )
1134 {
1135 //Overwrite all elements we can from [first, last)
1136 iterator cur = this->begin();
1137 const iterator end_it = this->end();
1138 for ( ; first != last && cur != end_it; ++cur, ++first){
1139 *cur = *first;
1140 }
1141
1142 if (first == last){
1143 //There are no more elements in the sequence, erase remaining
1144 T* const end_pos = this->priv_raw_end();
1145 const size_type n = static_cast<size_type>(end_pos - boost::movelib::iterator_to_raw_pointer(cur));
1146 this->priv_destroy_last_n(n);
1147 }
1148 else{
1149 //There are more elements in the range, insert the remaining ones
1150 this->insert(this->cend(), first, last);
1151 }
1152 }
1153
1154 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
1155 //! <b>Effects</b>: Assigns the the range [il.begin(), il.end()) to *this.
1156 //!
1157 //! <b>Throws</b>: If memory allocation throws or
1158 //! T's constructor from dereferencing iniializer_list iterator throws.
1159 //!
1160 BOOST_CONTAINER_FORCEINLINE void assign(std::initializer_list<T> il)
1161 {
1162 this->assign(il.begin(), il.end());
1163 }
1164 #endif
1165
1166 //! <b>Effects</b>: Assigns the the range [first, last) to *this.
1167 //!
1168 //! <b>Throws</b>: If memory allocation throws or T's copy/move constructor/assignment or
1169 //! T's constructor/assignment from dereferencing InpIt throws.
1170 //!
1171 //! <b>Complexity</b>: Linear to n.
1172 template <class FwdIt>
1173 void assign(FwdIt first, FwdIt last
1174 BOOST_CONTAINER_DOCIGN(BOOST_MOVE_I typename container_detail::disable_if_or
1175 < void
1176 BOOST_MOVE_I container_detail::is_same<alloc_version BOOST_MOVE_I version_0>
1177 BOOST_MOVE_I container_detail::is_convertible<FwdIt BOOST_MOVE_I size_type>
1178 BOOST_MOVE_I container_detail::is_input_iterator<FwdIt>
1179 >::type * = 0)
1180 )
1181 {
1182 //For Fwd iterators the standard only requires EmplaceConstructible and assignable from *first
1183 //so we can't do any backwards allocation
1184 const size_type input_sz = static_cast<size_type>(boost::container::iterator_distance(first, last));
1185 const size_type old_capacity = this->capacity();
1186 if(input_sz > old_capacity){ //If input range is too big, we need to reallocate
1187 size_type real_cap = 0;
1188 pointer reuse(this->m_holder.start());
1189 pointer const ret(this->m_holder.allocation_command(allocate_new|expand_fwd, input_sz, real_cap = input_sz, reuse));
1190 if(!reuse){ //New allocation, just emplace new values
1191 #ifdef BOOST_CONTAINER_VECTOR_ALLOC_STATS
1192 ++this->num_alloc;
1193 #endif
1194 pointer const old_p = this->m_holder.start();
1195 if(old_p){
1196 this->priv_destroy_all();
1197 allocator_traits_type::deallocate(this->m_holder.alloc(), old_p, old_capacity);
1198 }
1199 this->m_holder.start(ret);
1200 this->m_holder.capacity(real_cap);
1201 this->m_holder.m_size = 0;
1202 this->priv_uninitialized_construct_at_end(first, last);
1203 return;
1204 }
1205 else{
1206 #ifdef BOOST_CONTAINER_VECTOR_ALLOC_STATS
1207 ++this->num_expand_fwd;
1208 #endif
1209 this->m_holder.capacity(real_cap);
1210 //Forward expansion, use assignment + back deletion/construction that comes later
1211 }
1212 }
1213 //Overwrite all elements we can from [first, last)
1214 iterator cur = this->begin();
1215 const iterator end_it = this->end();
1216 for ( ; first != last && cur != end_it; ++cur, ++first){
1217 *cur = *first;
1218 }
1219
1220 if (first == last){
1221 //There are no more elements in the sequence, erase remaining
1222 this->priv_destroy_last_n(this->size() - input_sz);
1223 }
1224 else{
1225 //Uninitialized construct at end the remaining range
1226 this->priv_uninitialized_construct_at_end(first, last);
1227 }
1228 }
1229
1230 //! <b>Effects</b>: Assigns the n copies of val to *this.
1231 //!
1232 //! <b>Throws</b>: If memory allocation throws or
1233 //! T's copy/move constructor/assignment throws.
1234 //!
1235 //! <b>Complexity</b>: Linear to n.
1236 BOOST_CONTAINER_FORCEINLINE void assign(size_type n, const value_type& val)
1237 { this->assign(cvalue_iterator(val, n), cvalue_iterator()); }
1238
1239 //! <b>Effects</b>: Returns a copy of the internal allocator.
1240 //!
1241 //! <b>Throws</b>: If allocator's copy constructor throws.
1242 //!
1243 //! <b>Complexity</b>: Constant.
1244 allocator_type get_allocator() const BOOST_NOEXCEPT_OR_NOTHROW
1245 { return this->m_holder.alloc(); }
1246
1247 //! <b>Effects</b>: Returns a reference to the internal allocator.
1248 //!
1249 //! <b>Throws</b>: Nothing
1250 //!
1251 //! <b>Complexity</b>: Constant.
1252 //!
1253 //! <b>Note</b>: Non-standard extension.
1254 BOOST_CONTAINER_FORCEINLINE stored_allocator_type &get_stored_allocator() BOOST_NOEXCEPT_OR_NOTHROW
1255 { return this->m_holder.alloc(); }
1256
1257 //! <b>Effects</b>: Returns a reference to the internal allocator.
1258 //!
1259 //! <b>Throws</b>: Nothing
1260 //!
1261 //! <b>Complexity</b>: Constant.
1262 //!
1263 //! <b>Note</b>: Non-standard extension.
1264 BOOST_CONTAINER_FORCEINLINE const stored_allocator_type &get_stored_allocator() const BOOST_NOEXCEPT_OR_NOTHROW
1265 { return this->m_holder.alloc(); }
1266
1267 //////////////////////////////////////////////
1268 //
1269 // iterators
1270 //
1271 //////////////////////////////////////////////
1272
1273 //! <b>Effects</b>: Returns an iterator to the first element contained in the vector.
1274 //!
1275 //! <b>Throws</b>: Nothing.
1276 //!
1277 //! <b>Complexity</b>: Constant.
1278 BOOST_CONTAINER_FORCEINLINE iterator begin() BOOST_NOEXCEPT_OR_NOTHROW
1279 { return iterator(this->m_holder.start()); }
1280
1281 //! <b>Effects</b>: Returns a const_iterator to the first element contained in the vector.
1282 //!
1283 //! <b>Throws</b>: Nothing.
1284 //!
1285 //! <b>Complexity</b>: Constant.
1286 BOOST_CONTAINER_FORCEINLINE const_iterator begin() const BOOST_NOEXCEPT_OR_NOTHROW
1287 { return const_iterator(this->m_holder.start()); }
1288
1289 //! <b>Effects</b>: Returns an iterator to the end of the vector.
1290 //!
1291 //! <b>Throws</b>: Nothing.
1292 //!
1293 //! <b>Complexity</b>: Constant.
1294 BOOST_CONTAINER_FORCEINLINE iterator end() BOOST_NOEXCEPT_OR_NOTHROW
1295 { return iterator(this->m_holder.start() + this->m_holder.m_size); }
1296
1297 //! <b>Effects</b>: Returns a const_iterator to the end of the vector.
1298 //!
1299 //! <b>Throws</b>: Nothing.
1300 //!
1301 //! <b>Complexity</b>: Constant.
1302 BOOST_CONTAINER_FORCEINLINE const_iterator end() const BOOST_NOEXCEPT_OR_NOTHROW
1303 { return this->cend(); }
1304
1305 //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning
1306 //! of the reversed vector.
1307 //!
1308 //! <b>Throws</b>: Nothing.
1309 //!
1310 //! <b>Complexity</b>: Constant.
1311 BOOST_CONTAINER_FORCEINLINE reverse_iterator rbegin() BOOST_NOEXCEPT_OR_NOTHROW
1312 { return reverse_iterator(this->end()); }
1313
1314 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
1315 //! of the reversed vector.
1316 //!
1317 //! <b>Throws</b>: Nothing.
1318 //!
1319 //! <b>Complexity</b>: Constant.
1320 BOOST_CONTAINER_FORCEINLINE const_reverse_iterator rbegin() const BOOST_NOEXCEPT_OR_NOTHROW
1321 { return this->crbegin(); }
1322
1323 //! <b>Effects</b>: Returns a reverse_iterator pointing to the end
1324 //! of the reversed vector.
1325 //!
1326 //! <b>Throws</b>: Nothing.
1327 //!
1328 //! <b>Complexity</b>: Constant.
1329 BOOST_CONTAINER_FORCEINLINE reverse_iterator rend() BOOST_NOEXCEPT_OR_NOTHROW
1330 { return reverse_iterator(this->begin()); }
1331
1332 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
1333 //! of the reversed vector.
1334 //!
1335 //! <b>Throws</b>: Nothing.
1336 //!
1337 //! <b>Complexity</b>: Constant.
1338 BOOST_CONTAINER_FORCEINLINE const_reverse_iterator rend() const BOOST_NOEXCEPT_OR_NOTHROW
1339 { return this->crend(); }
1340
1341 //! <b>Effects</b>: Returns a const_iterator to the first element contained in the vector.
1342 //!
1343 //! <b>Throws</b>: Nothing.
1344 //!
1345 //! <b>Complexity</b>: Constant.
1346 BOOST_CONTAINER_FORCEINLINE const_iterator cbegin() const BOOST_NOEXCEPT_OR_NOTHROW
1347 { return const_iterator(this->m_holder.start()); }
1348
1349 //! <b>Effects</b>: Returns a const_iterator to the end of the vector.
1350 //!
1351 //! <b>Throws</b>: Nothing.
1352 //!
1353 //! <b>Complexity</b>: Constant.
1354 BOOST_CONTAINER_FORCEINLINE const_iterator cend() const BOOST_NOEXCEPT_OR_NOTHROW
1355 { return const_iterator(this->m_holder.start() + this->m_holder.m_size); }
1356
1357 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
1358 //! of the reversed vector.
1359 //!
1360 //! <b>Throws</b>: Nothing.
1361 //!
1362 //! <b>Complexity</b>: Constant.
1363 BOOST_CONTAINER_FORCEINLINE const_reverse_iterator crbegin() const BOOST_NOEXCEPT_OR_NOTHROW
1364 { return const_reverse_iterator(this->end());}
1365
1366 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
1367 //! of the reversed vector.
1368 //!
1369 //! <b>Throws</b>: Nothing.
1370 //!
1371 //! <b>Complexity</b>: Constant.
1372 BOOST_CONTAINER_FORCEINLINE const_reverse_iterator crend() const BOOST_NOEXCEPT_OR_NOTHROW
1373 { return const_reverse_iterator(this->begin()); }
1374
1375 //////////////////////////////////////////////
1376 //
1377 // capacity
1378 //
1379 //////////////////////////////////////////////
1380
1381 //! <b>Effects</b>: Returns true if the vector contains no elements.
1382 //!
1383 //! <b>Throws</b>: Nothing.
1384 //!
1385 //! <b>Complexity</b>: Constant.
1386 BOOST_CONTAINER_FORCEINLINE bool empty() const BOOST_NOEXCEPT_OR_NOTHROW
1387 { return !this->m_holder.m_size; }
1388
1389 //! <b>Effects</b>: Returns the number of the elements contained in the vector.
1390 //!
1391 //! <b>Throws</b>: Nothing.
1392 //!
1393 //! <b>Complexity</b>: Constant.
1394 BOOST_CONTAINER_FORCEINLINE size_type size() const BOOST_NOEXCEPT_OR_NOTHROW
1395 { return this->m_holder.m_size; }
1396
1397 //! <b>Effects</b>: Returns the largest possible size of the vector.
1398 //!
1399 //! <b>Throws</b>: Nothing.
1400 //!
1401 //! <b>Complexity</b>: Constant.
1402 BOOST_CONTAINER_FORCEINLINE size_type max_size() const BOOST_NOEXCEPT_OR_NOTHROW
1403 { return allocator_traits_type::max_size(this->m_holder.alloc()); }
1404
1405 //! <b>Effects</b>: Inserts or erases elements at the end such that
1406 //! the size becomes n. New elements are value initialized.
1407 //!
1408 //! <b>Throws</b>: If memory allocation throws, or T's copy/move or value initialization throws.
1409 //!
1410 //! <b>Complexity</b>: Linear to the difference between size() and new_size.
1411 void resize(size_type new_size)
1412 { this->priv_resize(new_size, value_init); }
1413
1414 //! <b>Effects</b>: Inserts or erases elements at the end such that
1415 //! the size becomes n. New elements are default initialized.
1416 //!
1417 //! <b>Throws</b>: If memory allocation throws, or T's copy/move or default initialization throws.
1418 //!
1419 //! <b>Complexity</b>: Linear to the difference between size() and new_size.
1420 //!
1421 //! <b>Note</b>: Non-standard extension
1422 void resize(size_type new_size, default_init_t)
1423 { this->priv_resize(new_size, default_init); }
1424
1425 //! <b>Effects</b>: Inserts or erases elements at the end such that
1426 //! the size becomes n. New elements are copy constructed from x.
1427 //!
1428 //! <b>Throws</b>: If memory allocation throws, or T's copy/move constructor throws.
1429 //!
1430 //! <b>Complexity</b>: Linear to the difference between size() and new_size.
1431 void resize(size_type new_size, const T& x)
1432 { this->priv_resize(new_size, x); }
1433
1434 //! <b>Effects</b>: Number of elements for which memory has been allocated.
1435 //! capacity() is always greater than or equal to size().
1436 //!
1437 //! <b>Throws</b>: Nothing.
1438 //!
1439 //! <b>Complexity</b>: Constant.
1440 BOOST_CONTAINER_FORCEINLINE size_type capacity() const BOOST_NOEXCEPT_OR_NOTHROW
1441 { return this->m_holder.capacity(); }
1442
1443 //! <b>Effects</b>: If n is less than or equal to capacity(), this call has no
1444 //! effect. Otherwise, it is a request for allocation of additional memory.
1445 //! If the request is successful, then capacity() is greater than or equal to
1446 //! n; otherwise, capacity() is unchanged. In either case, size() is unchanged.
1447 //!
1448 //! <b>Throws</b>: If memory allocation allocation throws or T's copy/move constructor throws.
1449 BOOST_CONTAINER_FORCEINLINE void reserve(size_type new_cap)
1450 {
1451 if (this->capacity() < new_cap){
1452 this->priv_reserve_no_capacity(new_cap, alloc_version());
1453 }
1454 }
1455
1456 //! <b>Effects</b>: Tries to deallocate the excess of memory created
1457 //! with previous allocations. The size of the vector is unchanged
1458 //!
1459 //! <b>Throws</b>: If memory allocation throws, or T's copy/move constructor throws.
1460 //!
1461 //! <b>Complexity</b>: Linear to size().
1462 BOOST_CONTAINER_FORCEINLINE void shrink_to_fit()
1463 { this->priv_shrink_to_fit(alloc_version()); }
1464
1465 //////////////////////////////////////////////
1466 //
1467 // element access
1468 //
1469 //////////////////////////////////////////////
1470
1471 //! <b>Requires</b>: !empty()
1472 //!
1473 //! <b>Effects</b>: Returns a reference to the first
1474 //! element of the container.
1475 //!
1476 //! <b>Throws</b>: Nothing.
1477 //!
1478 //! <b>Complexity</b>: Constant.
1479 reference front() BOOST_NOEXCEPT_OR_NOTHROW
1480 {
1481 BOOST_ASSERT(!this->empty());
1482 return *this->m_holder.start();
1483 }
1484
1485 //! <b>Requires</b>: !empty()
1486 //!
1487 //! <b>Effects</b>: Returns a const reference to the first
1488 //! element of the container.
1489 //!
1490 //! <b>Throws</b>: Nothing.
1491 //!
1492 //! <b>Complexity</b>: Constant.
1493 const_reference front() const BOOST_NOEXCEPT_OR_NOTHROW
1494 {
1495 BOOST_ASSERT(!this->empty());
1496 return *this->m_holder.start();
1497 }
1498
1499 //! <b>Requires</b>: !empty()
1500 //!
1501 //! <b>Effects</b>: Returns a reference to the last
1502 //! element of the container.
1503 //!
1504 //! <b>Throws</b>: Nothing.
1505 //!
1506 //! <b>Complexity</b>: Constant.
1507 reference back() BOOST_NOEXCEPT_OR_NOTHROW
1508 {
1509 BOOST_ASSERT(!this->empty());
1510 return this->m_holder.start()[this->m_holder.m_size - 1];
1511 }
1512
1513 //! <b>Requires</b>: !empty()
1514 //!
1515 //! <b>Effects</b>: Returns a const reference to the last
1516 //! element of the container.
1517 //!
1518 //! <b>Throws</b>: Nothing.
1519 //!
1520 //! <b>Complexity</b>: Constant.
1521 const_reference back() const BOOST_NOEXCEPT_OR_NOTHROW
1522 {
1523 BOOST_ASSERT(!this->empty());
1524 return this->m_holder.start()[this->m_holder.m_size - 1];
1525 }
1526
1527 //! <b>Requires</b>: size() > n.
1528 //!
1529 //! <b>Effects</b>: Returns a reference to the nth element
1530 //! from the beginning of the container.
1531 //!
1532 //! <b>Throws</b>: Nothing.
1533 //!
1534 //! <b>Complexity</b>: Constant.
1535 reference operator[](size_type n) BOOST_NOEXCEPT_OR_NOTHROW
1536 {
1537 BOOST_ASSERT(this->m_holder.m_size > n);
1538 return this->m_holder.start()[n];
1539 }
1540
1541 //! <b>Requires</b>: size() > n.
1542 //!
1543 //! <b>Effects</b>: Returns a const reference to the nth element
1544 //! from the beginning of the container.
1545 //!
1546 //! <b>Throws</b>: Nothing.
1547 //!
1548 //! <b>Complexity</b>: Constant.
1549 const_reference operator[](size_type n) const BOOST_NOEXCEPT_OR_NOTHROW
1550 {
1551 BOOST_ASSERT(this->m_holder.m_size > n);
1552 return this->m_holder.start()[n];
1553 }
1554
1555 //! <b>Requires</b>: size() >= n.
1556 //!
1557 //! <b>Effects</b>: Returns an iterator to the nth element
1558 //! from the beginning of the container. Returns end()
1559 //! if n == size().
1560 //!
1561 //! <b>Throws</b>: Nothing.
1562 //!
1563 //! <b>Complexity</b>: Constant.
1564 //!
1565 //! <b>Note</b>: Non-standard extension
1566 iterator nth(size_type n) BOOST_NOEXCEPT_OR_NOTHROW
1567 {
1568 BOOST_ASSERT(this->m_holder.m_size >= n);
1569 return iterator(this->m_holder.start()+n);
1570 }
1571
1572 //! <b>Requires</b>: size() >= n.
1573 //!
1574 //! <b>Effects</b>: Returns a const_iterator to the nth element
1575 //! from the beginning of the container. Returns end()
1576 //! if n == size().
1577 //!
1578 //! <b>Throws</b>: Nothing.
1579 //!
1580 //! <b>Complexity</b>: Constant.
1581 //!
1582 //! <b>Note</b>: Non-standard extension
1583 const_iterator nth(size_type n) const BOOST_NOEXCEPT_OR_NOTHROW
1584 {
1585 BOOST_ASSERT(this->m_holder.m_size >= n);
1586 return const_iterator(this->m_holder.start()+n);
1587 }
1588
1589 //! <b>Requires</b>: begin() <= p <= end().
1590 //!
1591 //! <b>Effects</b>: Returns the index of the element pointed by p
1592 //! and size() if p == end().
1593 //!
1594 //! <b>Throws</b>: Nothing.
1595 //!
1596 //! <b>Complexity</b>: Constant.
1597 //!
1598 //! <b>Note</b>: Non-standard extension
1599 size_type index_of(iterator p) BOOST_NOEXCEPT_OR_NOTHROW
1600 {
1601 //Range check assert done in priv_index_of
1602 return this->priv_index_of(vector_iterator_get_ptr(p));
1603 }
1604
1605 //! <b>Requires</b>: begin() <= p <= end().
1606 //!
1607 //! <b>Effects</b>: Returns the index of the element pointed by p
1608 //! and size() if p == end().
1609 //!
1610 //! <b>Throws</b>: Nothing.
1611 //!
1612 //! <b>Complexity</b>: Constant.
1613 //!
1614 //! <b>Note</b>: Non-standard extension
1615 size_type index_of(const_iterator p) const BOOST_NOEXCEPT_OR_NOTHROW
1616 {
1617 //Range check assert done in priv_index_of
1618 return this->priv_index_of(vector_iterator_get_ptr(p));
1619 }
1620
1621 //! <b>Requires</b>: size() > n.
1622 //!
1623 //! <b>Effects</b>: Returns a reference to the nth element
1624 //! from the beginning of the container.
1625 //!
1626 //! <b>Throws</b>: std::range_error if n >= size()
1627 //!
1628 //! <b>Complexity</b>: Constant.
1629 reference at(size_type n)
1630 {
1631 this->priv_throw_if_out_of_range(n);
1632 return this->m_holder.start()[n];
1633 }
1634
1635 //! <b>Requires</b>: size() > n.
1636 //!
1637 //! <b>Effects</b>: Returns a const reference to the nth element
1638 //! from the beginning of the container.
1639 //!
1640 //! <b>Throws</b>: std::range_error if n >= size()
1641 //!
1642 //! <b>Complexity</b>: Constant.
1643 const_reference at(size_type n) const
1644 {
1645 this->priv_throw_if_out_of_range(n);
1646 return this->m_holder.start()[n];
1647 }
1648
1649 //////////////////////////////////////////////
1650 //
1651 // data access
1652 //
1653 //////////////////////////////////////////////
1654
1655 //! <b>Returns</b>: A pointer such that [data(),data() + size()) is a valid range.
1656 //! For a non-empty vector, data() == &front().
1657 //!
1658 //! <b>Throws</b>: Nothing.
1659 //!
1660 //! <b>Complexity</b>: Constant.
1661 T* data() BOOST_NOEXCEPT_OR_NOTHROW
1662 { return this->priv_raw_begin(); }
1663
1664 //! <b>Returns</b>: A pointer such that [data(),data() + size()) is a valid range.
1665 //! For a non-empty vector, data() == &front().
1666 //!
1667 //! <b>Throws</b>: Nothing.
1668 //!
1669 //! <b>Complexity</b>: Constant.
1670 const T * data() const BOOST_NOEXCEPT_OR_NOTHROW
1671 { return this->priv_raw_begin(); }
1672
1673 //////////////////////////////////////////////
1674 //
1675 // modifiers
1676 //
1677 //////////////////////////////////////////////
1678
1679 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
1680 //! <b>Effects</b>: Inserts an object of type T constructed with
1681 //! std::forward<Args>(args)... in the end of the vector.
1682 //!
1683 //! <b>Returns</b>: A reference to the created object.
1684 //!
1685 //! <b>Throws</b>: If memory allocation throws or the in-place constructor throws or
1686 //! T's copy/move constructor throws.
1687 //!
1688 //! <b>Complexity</b>: Amortized constant time.
1689 template<class ...Args>
1690 BOOST_CONTAINER_FORCEINLINE reference emplace_back(BOOST_FWD_REF(Args)...args)
1691 {
1692 if (BOOST_LIKELY(this->room_enough())){
1693 //There is more memory, just construct a new object at the end
1694 T* const p = this->priv_raw_end();
1695 allocator_traits_type::construct(this->m_holder.alloc(), p, ::boost::forward<Args>(args)...);
1696 ++this->m_holder.m_size;
1697 return *p;
1698 }
1699 else{
1700 typedef container_detail::insert_emplace_proxy<Allocator, T*, Args...> type;
1701 return *this->priv_forward_range_insert_no_capacity
1702 (this->back_ptr(), 1, type(::boost::forward<Args>(args)...), alloc_version());
1703 }
1704 }
1705
1706 //! <b>Effects</b>: Inserts an object of type T constructed with
1707 //! std::forward<Args>(args)... in the end of the vector.
1708 //!
1709 //! <b>Throws</b>: If the in-place constructor throws.
1710 //!
1711 //! <b>Complexity</b>: Constant time.
1712 //!
1713 //! <b>Note</b>: Non-standard extension.
1714 template<class ...Args>
1715 BOOST_CONTAINER_FORCEINLINE bool stable_emplace_back(BOOST_FWD_REF(Args)...args)
1716 {
1717 const bool is_room_enough = this->room_enough() || (alloc_version::value == 2 && this->m_holder.try_expand_fwd(1u));
1718 if (BOOST_LIKELY(is_room_enough)){
1719 //There is more memory, just construct a new object at the end
1720 allocator_traits_type::construct(this->m_holder.alloc(), this->priv_raw_end(), ::boost::forward<Args>(args)...);
1721 ++this->m_holder.m_size;
1722 }
1723 return is_room_enough;
1724 }
1725
1726 //! <b>Requires</b>: position must be a valid iterator of *this.
1727 //!
1728 //! <b>Effects</b>: Inserts an object of type T constructed with
1729 //! std::forward<Args>(args)... before position
1730 //!
1731 //! <b>Throws</b>: If memory allocation throws or the in-place constructor throws or
1732 //! T's copy/move constructor/assignment throws.
1733 //!
1734 //! <b>Complexity</b>: If position is end(), amortized constant time
1735 //! Linear time otherwise.
1736 template<class ...Args>
1737 iterator emplace(const_iterator position, BOOST_FWD_REF(Args) ...args)
1738 {
1739 BOOST_ASSERT(this->priv_in_range_or_end(position));
1740 //Just call more general insert(pos, size, value) and return iterator
1741 typedef container_detail::insert_emplace_proxy<Allocator, T*, Args...> type;
1742 return this->priv_forward_range_insert( vector_iterator_get_ptr(position), 1
1743 , type(::boost::forward<Args>(args)...));
1744 }
1745
1746 #else // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
1747
1748 #define BOOST_CONTAINER_VECTOR_EMPLACE_CODE(N) \
1749 BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
1750 BOOST_CONTAINER_FORCEINLINE reference emplace_back(BOOST_MOVE_UREF##N)\
1751 {\
1752 if (BOOST_LIKELY(this->room_enough())){\
1753 T* const p = this->priv_raw_end();\
1754 allocator_traits_type::construct (this->m_holder.alloc()\
1755 , this->priv_raw_end() BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\
1756 ++this->m_holder.m_size;\
1757 return *p;\
1758 }\
1759 else{\
1760 typedef container_detail::insert_emplace_proxy_arg##N<Allocator, T* BOOST_MOVE_I##N BOOST_MOVE_TARG##N> type;\
1761 return *this->priv_forward_range_insert_no_capacity\
1762 ( this->back_ptr(), 1, type(BOOST_MOVE_FWD##N), alloc_version());\
1763 }\
1764 }\
1765 \
1766 BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
1767 BOOST_CONTAINER_FORCEINLINE bool stable_emplace_back(BOOST_MOVE_UREF##N)\
1768 {\
1769 const bool is_room_enough = this->room_enough() || (alloc_version::value == 2 && this->m_holder.try_expand_fwd(1u));\
1770 if (BOOST_LIKELY(is_room_enough)){\
1771 allocator_traits_type::construct (this->m_holder.alloc()\
1772 , this->priv_raw_end() BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\
1773 ++this->m_holder.m_size;\
1774 }\
1775 return is_room_enough;\
1776 }\
1777 \
1778 BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
1779 iterator emplace(const_iterator pos BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
1780 {\
1781 BOOST_ASSERT(this->priv_in_range_or_end(pos));\
1782 typedef container_detail::insert_emplace_proxy_arg##N<Allocator, T* BOOST_MOVE_I##N BOOST_MOVE_TARG##N> type;\
1783 return this->priv_forward_range_insert(vector_iterator_get_ptr(pos), 1, type(BOOST_MOVE_FWD##N));\
1784 }\
1785 //
1786 BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_VECTOR_EMPLACE_CODE)
1787 #undef BOOST_CONTAINER_VECTOR_EMPLACE_CODE
1788
1789 #endif
1790
1791 #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
1792 //! <b>Effects</b>: Inserts a copy of x at the end of the vector.
1793 //!
1794 //! <b>Throws</b>: If memory allocation throws or
1795 //! T's copy/move constructor throws.
1796 //!
1797 //! <b>Complexity</b>: Amortized constant time.
1798 void push_back(const T &x);
1799
1800 //! <b>Effects</b>: Constructs a new element in the end of the vector
1801 //! and moves the resources of x to this new element.
1802 //!
1803 //! <b>Throws</b>: If memory allocation throws or
1804 //! T's copy/move constructor throws.
1805 //!
1806 //! <b>Complexity</b>: Amortized constant time.
1807 void push_back(T &&x);
1808 #else
1809 BOOST_MOVE_CONVERSION_AWARE_CATCH(push_back, T, void, priv_push_back)
1810 #endif
1811
1812 #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
1813 //! <b>Requires</b>: position must be a valid iterator of *this.
1814 //!
1815 //! <b>Effects</b>: Insert a copy of x before position.
1816 //!
1817 //! <b>Throws</b>: If memory allocation throws or T's copy/move constructor/assignment throws.
1818 //!
1819 //! <b>Complexity</b>: If position is end(), amortized constant time
1820 //! Linear time otherwise.
1821 iterator insert(const_iterator position, const T &x);
1822
1823 //! <b>Requires</b>: position must be a valid iterator of *this.
1824 //!
1825 //! <b>Effects</b>: Insert a new element before position with x's resources.
1826 //!
1827 //! <b>Throws</b>: If memory allocation throws.
1828 //!
1829 //! <b>Complexity</b>: If position is end(), amortized constant time
1830 //! Linear time otherwise.
1831 iterator insert(const_iterator position, T &&x);
1832 #else
1833 BOOST_MOVE_CONVERSION_AWARE_CATCH_1ARG(insert, T, iterator, priv_insert, const_iterator, const_iterator)
1834 #endif
1835
1836 //! <b>Requires</b>: p must be a valid iterator of *this.
1837 //!
1838 //! <b>Effects</b>: Insert n copies of x before pos.
1839 //!
1840 //! <b>Returns</b>: an iterator to the first inserted element or p if n is 0.
1841 //!
1842 //! <b>Throws</b>: If memory allocation throws or T's copy/move constructor throws.
1843 //!
1844 //! <b>Complexity</b>: Linear to n.
1845 iterator insert(const_iterator p, size_type n, const T& x)
1846 {
1847 BOOST_ASSERT(this->priv_in_range_or_end(p));
1848 container_detail::insert_n_copies_proxy<Allocator, T*> proxy(x);
1849 return this->priv_forward_range_insert(vector_iterator_get_ptr(p), n, proxy);
1850 }
1851
1852 //! <b>Requires</b>: p must be a valid iterator of *this.
1853 //!
1854 //! <b>Effects</b>: Insert a copy of the [first, last) range before pos.
1855 //!
1856 //! <b>Returns</b>: an iterator to the first inserted element or pos if first == last.
1857 //!
1858 //! <b>Throws</b>: If memory allocation throws, T's constructor from a
1859 //! dereferenced InpIt throws or T's copy/move constructor/assignment throws.
1860 //!
1861 //! <b>Complexity</b>: Linear to boost::container::iterator_distance [first, last).
1862 template <class InIt>
1863 iterator insert(const_iterator pos, InIt first, InIt last
1864 #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
1865 , typename container_detail::disable_if_or
1866 < void
1867 , container_detail::is_convertible<InIt, size_type>
1868 , container_detail::is_not_input_iterator<InIt>
1869 >::type * = 0
1870 #endif
1871 )
1872 {
1873 BOOST_ASSERT(this->priv_in_range_or_end(pos));
1874 const size_type n_pos = pos - this->cbegin();
1875 iterator it(vector_iterator_get_ptr(pos));
1876 for(;first != last; ++first){
1877 it = this->emplace(it, *first);
1878 ++it;
1879 }
1880 return iterator(this->m_holder.start() + n_pos);
1881 }
1882
1883 #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
1884 template <class FwdIt>
1885 iterator insert(const_iterator pos, FwdIt first, FwdIt last
1886 , typename container_detail::disable_if_or
1887 < void
1888 , container_detail::is_convertible<FwdIt, size_type>
1889 , container_detail::is_input_iterator<FwdIt>
1890 >::type * = 0
1891 )
1892 {
1893 BOOST_ASSERT(this->priv_in_range_or_end(pos));
1894 container_detail::insert_range_proxy<Allocator, FwdIt, T*> proxy(first);
1895 return this->priv_forward_range_insert(vector_iterator_get_ptr(pos), boost::container::iterator_distance(first, last), proxy);
1896 }
1897 #endif
1898
1899 //! <b>Requires</b>: p must be a valid iterator of *this. num, must
1900 //! be equal to boost::container::iterator_distance(first, last)
1901 //!
1902 //! <b>Effects</b>: Insert a copy of the [first, last) range before pos.
1903 //!
1904 //! <b>Returns</b>: an iterator to the first inserted element or pos if first == last.
1905 //!
1906 //! <b>Throws</b>: If memory allocation throws, T's constructor from a
1907 //! dereferenced InpIt throws or T's copy/move constructor/assignment throws.
1908 //!
1909 //! <b>Complexity</b>: Linear to boost::container::iterator_distance [first, last).
1910 //!
1911 //! <b>Note</b>: This function avoids a linear operation to calculate boost::container::iterator_distance[first, last)
1912 //! for forward and bidirectional iterators, and a one by one insertion for input iterators. This is a
1913 //! a non-standard extension.
1914 #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
1915 template <class InIt>
1916 iterator insert(const_iterator pos, size_type num, InIt first, InIt last)
1917 {
1918 BOOST_ASSERT(this->priv_in_range_or_end(pos));
1919 BOOST_ASSERT(container_detail::is_input_iterator<InIt>::value ||
1920 num == static_cast<size_type>(boost::container::iterator_distance(first, last)));
1921 (void)last;
1922 container_detail::insert_range_proxy<Allocator, InIt, T*> proxy(first);
1923 return this->priv_forward_range_insert(vector_iterator_get_ptr(pos), num, proxy);
1924 }
1925 #endif
1926
1927 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
1928 //! <b>Requires</b>: position must be a valid iterator of *this.
1929 //!
1930 //! <b>Effects</b>: Insert a copy of the [il.begin(), il.end()) range before position.
1931 //!
1932 //! <b>Returns</b>: an iterator to the first inserted element or position if first == last.
1933 //!
1934 //! <b>Complexity</b>: Linear to the range [il.begin(), il.end()).
1935 iterator insert(const_iterator position, std::initializer_list<value_type> il)
1936 {
1937 //Assertion done in insert()
1938 return this->insert(position, il.begin(), il.end());
1939 }
1940 #endif
1941
1942 //! <b>Effects</b>: Removes the last element from the container.
1943 //!
1944 //! <b>Throws</b>: Nothing.
1945 //!
1946 //! <b>Complexity</b>: Constant time.
1947 void pop_back() BOOST_NOEXCEPT_OR_NOTHROW
1948 {
1949 BOOST_ASSERT(!this->empty());
1950 //Destroy last element
1951 this->priv_destroy_last();
1952 }
1953
1954 //! <b>Effects</b>: Erases the element at position pos.
1955 //!
1956 //! <b>Throws</b>: Nothing.
1957 //!
1958 //! <b>Complexity</b>: Linear to the elements between pos and the
1959 //! last element. Constant if pos is the last element.
1960 iterator erase(const_iterator position)
1961 {
1962 BOOST_ASSERT(this->priv_in_range(position));
1963 const pointer p = vector_iterator_get_ptr(position);
1964 T *const pos_ptr = boost::movelib::to_raw_pointer(p);
1965 T *const beg_ptr = this->priv_raw_begin();
1966 T *const new_end_ptr = ::boost::container::move(pos_ptr + 1, beg_ptr + this->m_holder.m_size, pos_ptr);
1967 //Move elements forward and destroy last
1968 this->priv_destroy_last(pos_ptr == new_end_ptr);
1969 return iterator(p);
1970 }
1971
1972 //! <b>Effects</b>: Erases the elements pointed by [first, last).
1973 //!
1974 //! <b>Throws</b>: Nothing.
1975 //!
1976 //! <b>Complexity</b>: Linear to the distance between first and last
1977 //! plus linear to the elements between pos and the last element.
1978 iterator erase(const_iterator first, const_iterator last)
1979 {
1980 BOOST_ASSERT(first == last ||
1981 (first < last && this->priv_in_range(first) && this->priv_in_range_or_end(last)));
1982 if (first != last){
1983 T* const old_end_ptr = this->priv_raw_end();
1984 T* const first_ptr = boost::movelib::to_raw_pointer(vector_iterator_get_ptr(first));
1985 T* const last_ptr = boost::movelib::to_raw_pointer(vector_iterator_get_ptr(last));
1986 T* const ptr = boost::movelib::to_raw_pointer(boost::container::move(last_ptr, old_end_ptr, first_ptr));
1987 this->priv_destroy_last_n(old_end_ptr - ptr);
1988 }
1989 return iterator(vector_iterator_get_ptr(first));
1990 }
1991
1992 //! <b>Effects</b>: Swaps the contents of *this and x.
1993 //!
1994 //! <b>Throws</b>: Nothing.
1995 //!
1996 //! <b>Complexity</b>: Constant.
1997 void swap(vector& x)
1998 BOOST_NOEXCEPT_IF( ((allocator_traits_type::propagate_on_container_swap::value
1999 || allocator_traits_type::is_always_equal::value) &&
2000 !container_detail::is_version<Allocator, 0>::value))
2001 {
2002 this->priv_swap(x, container_detail::bool_<container_detail::is_version<Allocator, 0>::value>());
2003 }
2004
2005 #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
2006
2007 //! <b>Effects</b>: Swaps the contents of *this and x.
2008 //!
2009 //! <b>Throws</b>: Nothing.
2010 //!
2011 //! <b>Complexity</b>: Linear
2012 //!
2013 //! <b>Note</b>: Non-standard extension to support static_vector
2014 template<class OtherAllocator>
2015 void swap(vector<T, OtherAllocator> & x
2016 , typename container_detail::enable_if_and
2017 < void
2018 , container_detail::is_version<OtherAllocator, 0>
2019 , container_detail::is_different<OtherAllocator, allocator_type>
2020 >::type * = 0
2021 )
2022 { this->m_holder.deep_swap(x.m_holder); }
2023
2024 #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
2025
2026 //! <b>Effects</b>: Erases all the elements of the vector.
2027 //!
2028 //! <b>Throws</b>: Nothing.
2029 //!
2030 //! <b>Complexity</b>: Linear to the number of elements in the container.
2031 void clear() BOOST_NOEXCEPT_OR_NOTHROW
2032 { this->priv_destroy_all(); }
2033
2034 //! <b>Effects</b>: Returns true if x and y are equal
2035 //!
2036 //! <b>Complexity</b>: Linear to the number of elements in the container.
2037 friend bool operator==(const vector& x, const vector& y)
2038 { return x.size() == y.size() && ::boost::container::algo_equal(x.begin(), x.end(), y.begin()); }
2039
2040 //! <b>Effects</b>: Returns true if x and y are unequal
2041 //!
2042 //! <b>Complexity</b>: Linear to the number of elements in the container.
2043 friend bool operator!=(const vector& x, const vector& y)
2044 { return !(x == y); }
2045
2046 //! <b>Effects</b>: Returns true if x is less than y
2047 //!
2048 //! <b>Complexity</b>: Linear to the number of elements in the container.
2049 friend bool operator<(const vector& x, const vector& y)
2050 {
2051 const_iterator first1(x.cbegin()), first2(y.cbegin());
2052 const const_iterator last1(x.cend()), last2(y.cend());
2053 for ( ; (first1 != last1) && (first2 != last2); ++first1, ++first2 ) {
2054 if (*first1 < *first2) return true;
2055 if (*first2 < *first1) return false;
2056 }
2057 return (first1 == last1) && (first2 != last2);
2058 }
2059
2060 //! <b>Effects</b>: Returns true if x is greater than y
2061 //!
2062 //! <b>Complexity</b>: Linear to the number of elements in the container.
2063 friend bool operator>(const vector& x, const vector& y)
2064 { return y < x; }
2065
2066 //! <b>Effects</b>: Returns true if x is equal or less than y
2067 //!
2068 //! <b>Complexity</b>: Linear to the number of elements in the container.
2069 friend bool operator<=(const vector& x, const vector& y)
2070 { return !(y < x); }
2071
2072 //! <b>Effects</b>: Returns true if x is equal or greater than y
2073 //!
2074 //! <b>Complexity</b>: Linear to the number of elements in the container.
2075 friend bool operator>=(const vector& x, const vector& y)
2076 { return !(x < y); }
2077
2078 //! <b>Effects</b>: x.swap(y)
2079 //!
2080 //! <b>Complexity</b>: Constant.
2081 friend void swap(vector& x, vector& y)
2082 { x.swap(y); }
2083
2084 #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
2085 //! <b>Effects</b>: If n is less than or equal to capacity(), this call has no
2086 //! effect. Otherwise, it is a request for allocation of additional memory
2087 //! (memory expansion) that will not invalidate iterators.
2088 //! If the request is successful, then capacity() is greater than or equal to
2089 //! n; otherwise, capacity() is unchanged. In either case, size() is unchanged.
2090 //!
2091 //! <b>Throws</b>: If memory allocation allocation throws or T's copy/move constructor throws.
2092 //!
2093 //! <b>Note</b>: Non-standard extension.
2094 bool stable_reserve(size_type new_cap)
2095 {
2096 const size_type cp = this->capacity();
2097 return cp >= new_cap || (alloc_version::value == 2 && this->m_holder.try_expand_fwd(new_cap - cp));
2098 }
2099
2100 //Absolutely experimental. This function might change, disappear or simply crash!
2101 template<class BiDirPosConstIt, class BiDirValueIt>
2102 void insert_ordered_at(const size_type element_count, BiDirPosConstIt last_position_it, BiDirValueIt last_value_it)
2103 {
2104 typedef container_detail::vector_insert_ordered_cursor<BiDirPosConstIt, BiDirValueIt> inserter_t;
2105 return this->priv_insert_ordered_at(element_count, inserter_t(last_position_it, last_value_it));
2106 }
2107
2108 template<class BidirIt>
2109 void merge(BidirIt first, BidirIt last)
2110 { this->merge(first, last, value_less()); }
2111
2112 template<class BidirIt, class Compare>
2113 void merge(BidirIt first, BidirIt last, Compare comp)
2114 { this->priv_merge(container_detail::false_type(), first, last, comp); }
2115
2116 template<class BidirIt>
2117 void merge_unique(BidirIt first, BidirIt last)
2118 { this->priv_merge(container_detail::true_type(), first, last, value_less()); }
2119
2120 template<class BidirIt, class Compare>
2121 void merge_unique(BidirIt first, BidirIt last, Compare comp)
2122 { this->priv_merge(container_detail::true_type(), first, last, comp); }
2123
2124 private:
2125 template<class PositionValue>
2126 void priv_insert_ordered_at(const size_type element_count, PositionValue position_value)
2127 {
2128 const size_type old_size_pos = this->size();
2129 this->reserve(old_size_pos + element_count);
2130 T* const begin_ptr = this->priv_raw_begin();
2131 size_type insertions_left = element_count;
2132 size_type prev_pos = old_size_pos;
2133 size_type old_hole_size = element_count;
2134
2135 //Exception rollback. If any copy throws before the hole is filled, values
2136 //already inserted/copied at the end of the buffer will be destroyed.
2137 typename value_traits::ArrayDestructor past_hole_values_destroyer
2138 (begin_ptr + old_size_pos + element_count, this->m_holder.alloc(), size_type(0u));
2139 //Loop for each insertion backwards, first moving the elements after the insertion point,
2140 //then inserting the element.
2141 while(insertions_left){
2142 --position_value;
2143 size_type const pos = position_value.get_pos();
2144 BOOST_ASSERT(pos != size_type(-1) && pos <= old_size_pos && pos <= prev_pos);
2145 //If needed shift the range after the insertion point and the previous insertion point.
2146 //Function will take care if the shift crosses the size() boundary, using copy/move
2147 //or uninitialized copy/move if necessary.
2148 size_type new_hole_size = (pos != prev_pos)
2149 ? priv_insert_ordered_at_shift_range(pos, prev_pos, this->size(), insertions_left)
2150 : old_hole_size
2151 ;
2152 if(new_hole_size){
2153 //The hole was reduced by priv_insert_ordered_at_shift_range so expand exception rollback range backwards
2154 past_hole_values_destroyer.increment_size_backwards(prev_pos - pos);
2155 //Insert the new value in the hole
2156 allocator_traits_type::construct(this->m_holder.alloc(), begin_ptr + pos + insertions_left - 1, position_value.get_val());
2157 if(--new_hole_size){
2158 //The hole was reduced by the new insertion by one
2159 past_hole_values_destroyer.increment_size_backwards(size_type(1u));
2160 }
2161 else{
2162 //Hole was just filled, disable exception rollback and change vector size
2163 past_hole_values_destroyer.release();
2164 this->m_holder.m_size += element_count;
2165 }
2166 }
2167 else{
2168 if(old_hole_size){
2169 //Hole was just filled by priv_insert_ordered_at_shift_range, disable exception rollback and change vector size
2170 past_hole_values_destroyer.release();
2171 this->m_holder.m_size += element_count;
2172 }
2173 //Insert the new value in the already constructed range
2174 begin_ptr[pos + insertions_left - 1] = position_value.get_val();
2175 }
2176 --insertions_left;
2177 old_hole_size = new_hole_size;
2178 prev_pos = pos;
2179 }
2180 }
2181
2182 template<class UniqueBool, class BidirIt, class Compare>
2183 void priv_merge(UniqueBool, BidirIt first, BidirIt last, Compare comp)
2184 {
2185 size_type const n = static_cast<size_type>(boost::container::iterator_distance(first, last));
2186 size_type const s = this->size();
2187 if(BOOST_LIKELY(s)){
2188 size_type const c = this->capacity();
2189 size_type const free_c = (c - s);
2190 //Use a new buffer if current one is too small for new elements
2191 if(free_c < n){
2192 this->priv_merge_in_new_buffer(UniqueBool(), first, n, comp, alloc_version());
2193 }
2194 else{
2195 T *raw_pos = boost::movelib::iterator_to_raw_pointer(this->insert(this->cend(), first, last));
2196 T *raw_beg = this->priv_raw_begin();
2197 T *raw_end = this->priv_raw_end();
2198 boost::movelib::adaptive_merge(raw_beg, raw_pos, raw_end, comp, raw_end, free_c - n);
2199 if(UniqueBool::value){
2200 size_type const count =
2201 static_cast<size_type>(raw_end - boost::movelib::unique(raw_beg, raw_end, boost::movelib::negate<Compare>(comp)));
2202 this->priv_destroy_last_n(count);
2203 }
2204 }
2205 }
2206 else{
2207 this->insert(this->cend(), n, first, last);
2208 }
2209 }
2210
2211 template<class UniqueBool, class FwdIt, class Compare>
2212 void priv_merge_in_new_buffer(UniqueBool, FwdIt, size_type, Compare, version_0)
2213 {
2214 throw_bad_alloc();
2215 }
2216
2217 template<class UniqueBool, class FwdIt, class Compare, class Version>
2218 void priv_merge_in_new_buffer(UniqueBool, FwdIt first, size_type n, Compare comp, Version)
2219 {
2220 size_type const new_size = this->size() + n;
2221 size_type new_cap = new_size;
2222 pointer p = pointer();
2223 pointer const new_storage = this->m_holder.allocation_command(allocate_new, new_size, new_cap, p);
2224
2225 BOOST_ASSERT((new_cap >= this->size() ) && (new_cap - this->size()) >= n);
2226 allocator_type &a = this->m_holder.alloc();
2227 typename value_traits::ArrayDeallocator new_buffer_deallocator(new_storage, a, new_cap);
2228 typename value_traits::ArrayDestructor new_values_destroyer(new_storage, a, 0u);
2229 T* pbeg = this->priv_raw_begin();
2230 size_type const old_size = this->size();
2231 T* const pend = pbeg + old_size;
2232 T* d_first = boost::movelib::to_raw_pointer(new_storage);
2233 size_type added = n;
2234 //Merge in new buffer loop
2235 while(1){
2236 if(!n) {
2237 ::boost::container::uninitialized_move_alloc(this->m_holder.alloc(), pbeg, pend, d_first);
2238 break;
2239 }
2240 else if(pbeg == pend) {
2241 ::boost::container::uninitialized_move_alloc_n(this->m_holder.alloc(), first, n, d_first);
2242 break;
2243 }
2244 //maintain stability moving external values only if they are strictly less
2245 else if(comp(*first, *pbeg)) {
2246 allocator_traits_type::construct( this->m_holder.alloc(), d_first, *first );
2247 new_values_destroyer.increment_size(1u);
2248 ++first;
2249 --n;
2250 ++d_first;
2251 }
2252 else if(UniqueBool::value && !comp(*pbeg, *first)){
2253 ++first;
2254 --n;
2255 --added;
2256 }
2257 else{
2258 allocator_traits_type::construct( this->m_holder.alloc(), d_first, boost::move(*pbeg) );
2259 new_values_destroyer.increment_size(1u);
2260 ++pbeg;
2261 ++d_first;
2262 }
2263 }
2264
2265 //Nothrow operations
2266 pointer const old_p = this->m_holder.start();
2267 size_type const old_cap = this->m_holder.capacity();
2268 boost::container::destroy_alloc_n(a, boost::movelib::to_raw_pointer(old_p), old_size);
2269 allocator_traits_type::deallocate(a, old_p, old_cap);
2270 this->m_holder.m_size = old_size + added;
2271 this->m_holder.start(new_storage);
2272 this->m_holder.capacity(new_cap);
2273 new_buffer_deallocator.release();
2274 new_values_destroyer.release();
2275 }
2276
2277 bool room_enough() const
2278 { return this->m_holder.m_size < this->m_holder.capacity(); }
2279
2280 pointer back_ptr() const
2281 { return this->m_holder.start() + this->m_holder.m_size; }
2282
2283 size_type priv_index_of(pointer p) const
2284 {
2285 BOOST_ASSERT(this->m_holder.start() <= p);
2286 BOOST_ASSERT(p <= (this->m_holder.start()+this->size()));
2287 return static_cast<size_type>(p - this->m_holder.start());
2288 }
2289
2290 template<class OtherAllocator>
2291 void priv_move_assign(BOOST_RV_REF_BEG vector<T, OtherAllocator> BOOST_RV_REF_END x
2292 , typename container_detail::enable_if_c
2293 < container_detail::is_version<OtherAllocator, 0>::value >::type * = 0)
2294 {
2295 if(!container_detail::is_same<OtherAllocator, allocator_type>::value &&
2296 this->capacity() < x.size()){
2297 throw_bad_alloc();
2298 }
2299 T* const this_start = this->priv_raw_begin();
2300 T* const other_start = x.priv_raw_begin();
2301 const size_type this_sz = m_holder.m_size;
2302 const size_type other_sz = static_cast<size_type>(x.m_holder.m_size);
2303 boost::container::move_assign_range_alloc_n(this->m_holder.alloc(), other_start, other_sz, this_start, this_sz);
2304 this->m_holder.m_size = other_sz;
2305 }
2306
2307 template<class OtherAllocator>
2308 void priv_move_assign(BOOST_RV_REF_BEG vector<T, OtherAllocator> BOOST_RV_REF_END x
2309 , typename container_detail::disable_if_or
2310 < void
2311 , container_detail::is_version<OtherAllocator, 0>
2312 , container_detail::is_different<OtherAllocator, allocator_type>
2313 >::type * = 0)
2314 {
2315 //for move assignment, no aliasing (&x != this) is assummed.
2316 BOOST_ASSERT(this != &x);
2317 allocator_type &this_alloc = this->m_holder.alloc();
2318 allocator_type &x_alloc = x.m_holder.alloc();
2319 const bool propagate_alloc = allocator_traits_type::propagate_on_container_move_assignment::value;
2320
2321 const bool is_propagable_from_x = is_propagable_from(x_alloc, x.m_holder.start(), this_alloc, propagate_alloc);
2322 const bool is_propagable_from_t = is_propagable_from(this_alloc, m_holder.start(), x_alloc, propagate_alloc);
2323 const bool are_both_propagable = is_propagable_from_x && is_propagable_from_t;
2324
2325 //Resources can be transferred if both allocators are
2326 //going to be equal after this function (either propagated or already equal)
2327 if(are_both_propagable){
2328 //Destroy objects but retain memory in case x reuses it in the future
2329 this->clear();
2330 this->m_holder.swap_resources(x.m_holder);
2331 }
2332 else if(is_propagable_from_x){
2333 this->clear();
2334 allocator_traits_type::deallocate(this->m_holder.alloc(), this->m_holder.m_start, this->m_holder.m_capacity);
2335 this->m_holder.steal_resources(x.m_holder);
2336 }
2337 //Else do a one by one move
2338 else{
2339 this->assign( boost::make_move_iterator(boost::movelib::iterator_to_raw_pointer(x.begin()))
2340 , boost::make_move_iterator(boost::movelib::iterator_to_raw_pointer(x.end() ))
2341 );
2342 }
2343 //Move allocator if needed
2344 container_detail::move_alloc(this_alloc, x_alloc, container_detail::bool_<propagate_alloc>());
2345 }
2346
2347 template<class OtherAllocator>
2348 void priv_copy_assign(const vector<T, OtherAllocator> &x
2349 , typename container_detail::enable_if_c
2350 < container_detail::is_version<OtherAllocator, 0>::value >::type * = 0)
2351 {
2352 if(!container_detail::is_same<OtherAllocator, allocator_type>::value &&
2353 this->capacity() < x.size()){
2354 throw_bad_alloc();
2355 }
2356 T* const this_start = this->priv_raw_begin();
2357 T* const other_start = x.priv_raw_begin();
2358 const size_type this_sz = m_holder.m_size;
2359 const size_type other_sz = static_cast<size_type>(x.m_holder.m_size);
2360 boost::container::copy_assign_range_alloc_n(this->m_holder.alloc(), other_start, other_sz, this_start, this_sz);
2361 this->m_holder.m_size = other_sz;
2362 }
2363
2364 template<class OtherAllocator>
2365 typename container_detail::disable_if_or
2366 < void
2367 , container_detail::is_version<OtherAllocator, 0>
2368 , container_detail::is_different<OtherAllocator, allocator_type>
2369 >::type
2370 priv_copy_assign(const vector<T, OtherAllocator> &x)
2371 {
2372 allocator_type &this_alloc = this->m_holder.alloc();
2373 const allocator_type &x_alloc = x.m_holder.alloc();
2374 container_detail::bool_<allocator_traits_type::
2375 propagate_on_container_copy_assignment::value> flag;
2376 if(flag && this_alloc != x_alloc){
2377 this->clear();
2378 this->shrink_to_fit();
2379 }
2380 container_detail::assign_alloc(this_alloc, x_alloc, flag);
2381 this->assign( x.priv_raw_begin(), x.priv_raw_end() );
2382 }
2383
2384 template<class Vector> //Template it to avoid it in explicit instantiations
2385 void priv_swap(Vector &x, container_detail::true_type) //version_0
2386 { this->m_holder.deep_swap(x.m_holder); }
2387
2388 template<class Vector> //Template it to avoid it in explicit instantiations
2389 void priv_swap(Vector &x, container_detail::false_type) //version_N
2390 {
2391 const bool propagate_alloc = allocator_traits_type::propagate_on_container_swap::value;
2392 if(are_swap_propagable( this->get_stored_allocator(), this->m_holder.start()
2393 , x.get_stored_allocator(), x.m_holder.start(), propagate_alloc)){
2394 //Just swap internals
2395 this->m_holder.swap_resources(x.m_holder);
2396 }
2397 else{
2398 //Else swap element by element...
2399 bool const t_smaller = this->size() < x.size();
2400 vector &sml = t_smaller ? *this : x;
2401 vector &big = t_smaller ? x : *this;
2402
2403 size_type const common_elements = sml.size();
2404 for(size_type i = 0; i != common_elements; ++i){
2405 boost::adl_move_swap(sml[i], big[i]);
2406 }
2407 //... and move-insert the remaining range
2408 sml.insert( sml.cend()
2409 , boost::make_move_iterator(boost::movelib::iterator_to_raw_pointer(big.nth(common_elements)))
2410 , boost::make_move_iterator(boost::movelib::iterator_to_raw_pointer(big.end()))
2411 );
2412 //Destroy remaining elements
2413 big.erase(big.nth(common_elements), big.cend());
2414 }
2415 //And now swap the allocator
2416 container_detail::swap_alloc(this->m_holder.alloc(), x.m_holder.alloc(), container_detail::bool_<propagate_alloc>());
2417 }
2418
2419 void priv_reserve_no_capacity(size_type, version_0)
2420 { throw_bad_alloc(); }
2421
2422 container_detail::insert_range_proxy<Allocator, boost::move_iterator<T*>, T*> priv_dummy_empty_proxy()
2423 {
2424 return container_detail::insert_range_proxy<Allocator, boost::move_iterator<T*>, T*>
2425 (::boost::make_move_iterator((T *)0));
2426 }
2427
2428 void priv_reserve_no_capacity(size_type new_cap, version_1)
2429 {
2430 //There is not enough memory, allocate a new buffer
2431 //Pass the hint so that allocators can take advantage of this.
2432 pointer const p = allocator_traits_type::allocate(this->m_holder.alloc(), new_cap, this->m_holder.m_start);
2433 //We will reuse insert code, so create a dummy input iterator
2434 this->priv_forward_range_insert_new_allocation
2435 ( boost::movelib::to_raw_pointer(p), new_cap, this->priv_raw_end(), 0, this->priv_dummy_empty_proxy());
2436 }
2437
2438 void priv_reserve_no_capacity(size_type new_cap, version_2)
2439 {
2440 //There is not enough memory, allocate a new
2441 //buffer or expand the old one.
2442 bool same_buffer_start;
2443 size_type real_cap = 0;
2444 pointer reuse(this->m_holder.start());
2445 pointer const ret(this->m_holder.allocation_command(allocate_new | expand_fwd | expand_bwd, new_cap, real_cap = new_cap, reuse));
2446
2447 //Check for forward expansion
2448 same_buffer_start = reuse && this->m_holder.start() == ret;
2449 if(same_buffer_start){
2450 #ifdef BOOST_CONTAINER_VECTOR_ALLOC_STATS
2451 ++this->num_expand_fwd;
2452 #endif
2453 this->m_holder.capacity(real_cap);
2454 }
2455 else{ //If there is no forward expansion, move objects, we will reuse insertion code
2456 T * const new_mem = boost::movelib::to_raw_pointer(ret);
2457 T * const ins_pos = this->priv_raw_end();
2458 if(reuse){ //Backwards (and possibly forward) expansion
2459 #ifdef BOOST_CONTAINER_VECTOR_ALLOC_STATS
2460 ++this->num_expand_bwd;
2461 #endif
2462 this->priv_forward_range_insert_expand_backwards
2463 ( new_mem , real_cap, ins_pos, 0, this->priv_dummy_empty_proxy());
2464 }
2465 else{ //New buffer
2466 #ifdef BOOST_CONTAINER_VECTOR_ALLOC_STATS
2467 ++this->num_alloc;
2468 #endif
2469 this->priv_forward_range_insert_new_allocation
2470 ( new_mem, real_cap, ins_pos, 0, this->priv_dummy_empty_proxy());
2471 }
2472 }
2473 }
2474
2475 void priv_destroy_last(const bool moved = false) BOOST_NOEXCEPT_OR_NOTHROW
2476 {
2477 (void)moved;
2478 if(!(value_traits::trivial_dctr || (value_traits::trivial_dctr_after_move && moved))){
2479 value_type* const p = this->priv_raw_end() - 1;
2480 allocator_traits_type::destroy(this->get_stored_allocator(), p);
2481 }
2482 --this->m_holder.m_size;
2483 }
2484
2485 void priv_destroy_last_n(const size_type n) BOOST_NOEXCEPT_OR_NOTHROW
2486 {
2487 BOOST_ASSERT(n <= this->m_holder.m_size);
2488 if(!value_traits::trivial_dctr){
2489 T* const destroy_pos = this->priv_raw_begin() + (this->m_holder.m_size-n);
2490 boost::container::destroy_alloc_n(this->get_stored_allocator(), destroy_pos, n);
2491 }
2492 this->m_holder.m_size -= n;
2493 }
2494
2495 template<class InpIt>
2496 void priv_uninitialized_construct_at_end(InpIt first, InpIt last)
2497 {
2498 T* const old_end_pos = this->priv_raw_end();
2499 T* const new_end_pos = boost::container::uninitialized_copy_alloc(this->m_holder.alloc(), first, last, old_end_pos);
2500 this->m_holder.m_size += new_end_pos - old_end_pos;
2501 }
2502
2503 void priv_destroy_all() BOOST_NOEXCEPT_OR_NOTHROW
2504 {
2505 boost::container::destroy_alloc_n
2506 (this->get_stored_allocator(), this->priv_raw_begin(), this->m_holder.m_size);
2507 this->m_holder.m_size = 0;
2508 }
2509
2510 template<class U>
2511 iterator priv_insert(const const_iterator &p, BOOST_FWD_REF(U) x)
2512 {
2513 BOOST_ASSERT(this->priv_in_range_or_end(p));
2514 return this->priv_forward_range_insert
2515 ( vector_iterator_get_ptr(p), 1, container_detail::get_insert_value_proxy<T*, Allocator>(::boost::forward<U>(x)));
2516 }
2517
2518 container_detail::insert_copy_proxy<Allocator, T*> priv_single_insert_proxy(const T &x)
2519 { return container_detail::insert_copy_proxy<Allocator, T*> (x); }
2520
2521 container_detail::insert_move_proxy<Allocator, T*> priv_single_insert_proxy(BOOST_RV_REF(T) x)
2522 { return container_detail::insert_move_proxy<Allocator, T*> (x); }
2523
2524 template <class U>
2525 void priv_push_back(BOOST_FWD_REF(U) u)
2526 {
2527 if (BOOST_LIKELY(this->room_enough())){
2528 //There is more memory, just construct a new object at the end
2529 allocator_traits_type::construct
2530 ( this->m_holder.alloc(), this->priv_raw_end(), ::boost::forward<U>(u) );
2531 ++this->m_holder.m_size;
2532 }
2533 else{
2534 this->priv_forward_range_insert_no_capacity
2535 ( this->back_ptr(), 1
2536 , this->priv_single_insert_proxy(::boost::forward<U>(u)), alloc_version());
2537 }
2538 }
2539
2540 container_detail::insert_n_copies_proxy<Allocator, T*> priv_resize_proxy(const T &x)
2541 { return container_detail::insert_n_copies_proxy<Allocator, T*>(x); }
2542
2543 container_detail::insert_default_initialized_n_proxy<Allocator, T*> priv_resize_proxy(default_init_t)
2544 { return container_detail::insert_default_initialized_n_proxy<Allocator, T*>(); }
2545
2546 container_detail::insert_value_initialized_n_proxy<Allocator, T*> priv_resize_proxy(value_init_t)
2547 { return container_detail::insert_value_initialized_n_proxy<Allocator, T*>(); }
2548
2549 template <class U>
2550 void priv_resize(size_type new_size, const U& u)
2551 {
2552 const size_type sz = this->size();
2553 if (new_size < sz){
2554 //Destroy last elements
2555 this->priv_destroy_last_n(sz - new_size);
2556 }
2557 else{
2558 const size_type n = new_size - this->size();
2559 this->priv_forward_range_insert_at_end(n, this->priv_resize_proxy(u), alloc_version());
2560 }
2561 }
2562
2563 void priv_shrink_to_fit(version_0) BOOST_NOEXCEPT_OR_NOTHROW
2564 {}
2565
2566 void priv_shrink_to_fit(version_1)
2567 {
2568 const size_type cp = this->m_holder.capacity();
2569 if(cp){
2570 const size_type sz = this->size();
2571 if(!sz){
2572 allocator_traits_type::deallocate(this->m_holder.alloc(), this->m_holder.m_start, cp);
2573 this->m_holder.m_start = pointer();
2574 this->m_holder.m_capacity = 0;
2575 }
2576 else if(sz < cp){
2577 //Allocate a new buffer.
2578 //Pass the hint so that allocators can take advantage of this.
2579 pointer const p = allocator_traits_type::allocate(this->m_holder.alloc(), sz, this->m_holder.m_start);
2580
2581 //We will reuse insert code, so create a dummy input iterator
2582 #ifdef BOOST_CONTAINER_VECTOR_ALLOC_STATS
2583 ++this->num_alloc;
2584 #endif
2585 this->priv_forward_range_insert_new_allocation
2586 ( boost::movelib::to_raw_pointer(p), sz
2587 , this->priv_raw_begin(), 0, this->priv_dummy_empty_proxy());
2588 }
2589 }
2590 }
2591
2592 void priv_shrink_to_fit(version_2) BOOST_NOEXCEPT_OR_NOTHROW
2593 {
2594 const size_type cp = this->m_holder.capacity();
2595 if(cp){
2596 const size_type sz = this->size();
2597 if(!sz){
2598 allocator_traits_type::deallocate(this->m_holder.alloc(), this->m_holder.m_start, cp);
2599 this->m_holder.m_start = pointer();
2600 this->m_holder.m_capacity = 0;
2601 }
2602 else{
2603 size_type received_size = sz;
2604 pointer reuse(this->m_holder.start());
2605 if(this->m_holder.allocation_command
2606 (shrink_in_place | nothrow_allocation, cp, received_size, reuse)){
2607 this->m_holder.capacity(received_size);
2608 #ifdef BOOST_CONTAINER_VECTOR_ALLOC_STATS
2609 ++this->num_shrink;
2610 #endif
2611 }
2612 }
2613 }
2614 }
2615
2616 template <class InsertionProxy>
2617 iterator priv_forward_range_insert_no_capacity
2618 (const pointer &pos, const size_type, const InsertionProxy , version_0)
2619 {
2620 throw_bad_alloc();
2621 return iterator(pos);
2622 }
2623
2624 template <class InsertionProxy>
2625 iterator priv_forward_range_insert_no_capacity
2626 (const pointer &pos, const size_type n, const InsertionProxy insert_range_proxy, version_1)
2627 {
2628 //Check if we have enough memory or try to expand current memory
2629 const size_type n_pos = pos - this->m_holder.start();
2630 T *const raw_pos = boost::movelib::to_raw_pointer(pos);
2631
2632 const size_type new_cap = this->m_holder.next_capacity(n);
2633 //Pass the hint so that allocators can take advantage of this.
2634 T * const new_buf = boost::movelib::to_raw_pointer
2635 (allocator_traits_type::allocate(this->m_holder.alloc(), new_cap, this->m_holder.m_start));
2636 #ifdef BOOST_CONTAINER_VECTOR_ALLOC_STATS
2637 ++this->num_alloc;
2638 #endif
2639 this->priv_forward_range_insert_new_allocation
2640 ( new_buf, new_cap, raw_pos, n, insert_range_proxy);
2641 return iterator(this->m_holder.start() + n_pos);
2642 }
2643
2644 template <class InsertionProxy>
2645 iterator priv_forward_range_insert_no_capacity
2646 (const pointer &pos, const size_type n, const InsertionProxy insert_range_proxy, version_2)
2647 {
2648 //Check if we have enough memory or try to expand current memory
2649 T *const raw_pos = boost::movelib::to_raw_pointer(pos);
2650 const size_type n_pos = raw_pos - this->priv_raw_begin();
2651
2652 //There is not enough memory, allocate a new
2653 //buffer or expand the old one.
2654 size_type real_cap = this->m_holder.next_capacity(n);
2655 pointer reuse(this->m_holder.start());
2656 pointer const ret (this->m_holder.allocation_command
2657 (allocate_new | expand_fwd | expand_bwd, this->m_holder.m_size + n, real_cap, reuse));
2658
2659 //Buffer reallocated
2660 if(reuse){
2661 //Forward expansion, delay insertion
2662 if(this->m_holder.start() == ret){
2663 #ifdef BOOST_CONTAINER_VECTOR_ALLOC_STATS
2664 ++this->num_expand_fwd;
2665 #endif
2666 this->m_holder.capacity(real_cap);
2667 //Expand forward
2668 this->priv_forward_range_insert_expand_forward(raw_pos, n, insert_range_proxy);
2669 }
2670 //Backwards (and possibly forward) expansion
2671 else{
2672 #ifdef BOOST_CONTAINER_VECTOR_ALLOC_STATS
2673 ++this->num_expand_bwd;
2674 #endif
2675 this->priv_forward_range_insert_expand_backwards
2676 (boost::movelib::to_raw_pointer(ret), real_cap, raw_pos, n, insert_range_proxy);
2677 }
2678 }
2679 //New buffer
2680 else{
2681 #ifdef BOOST_CONTAINER_VECTOR_ALLOC_STATS
2682 ++this->num_alloc;
2683 #endif
2684 this->priv_forward_range_insert_new_allocation
2685 ( boost::movelib::to_raw_pointer(ret), real_cap, raw_pos, n, insert_range_proxy);
2686 }
2687
2688 return iterator(this->m_holder.start() + n_pos);
2689 }
2690
2691 template <class InsertionProxy>
2692 iterator priv_forward_range_insert
2693 (const pointer &pos, const size_type n, const InsertionProxy insert_range_proxy)
2694 {
2695 BOOST_ASSERT(this->m_holder.capacity() >= this->m_holder.m_size);
2696 //Check if we have enough memory or try to expand current memory
2697 const size_type remaining = this->m_holder.capacity() - this->m_holder.m_size;
2698
2699 bool same_buffer_start = n <= remaining;
2700 if (!same_buffer_start){
2701 return priv_forward_range_insert_no_capacity(pos, n, insert_range_proxy, alloc_version());
2702 }
2703 else{
2704 //Expand forward
2705 T *const raw_pos = boost::movelib::to_raw_pointer(pos);
2706 const size_type n_pos = raw_pos - this->priv_raw_begin();
2707 this->priv_forward_range_insert_expand_forward(raw_pos, n, insert_range_proxy);
2708 return iterator(this->m_holder.start() + n_pos);
2709 }
2710 }
2711
2712 template <class InsertionProxy>
2713 iterator priv_forward_range_insert_at_end
2714 (const size_type n, const InsertionProxy insert_range_proxy, version_0)
2715 {
2716 //Check if we have enough memory or try to expand current memory
2717 const size_type remaining = this->m_holder.capacity() - this->m_holder.m_size;
2718
2719 if (n > remaining){
2720 //This will trigger an error
2721 throw_bad_alloc();
2722 }
2723 this->priv_forward_range_insert_at_end_expand_forward(n, insert_range_proxy);
2724 return this->end();
2725 }
2726
2727 template <class InsertionProxy, class AllocVersion>
2728 iterator priv_forward_range_insert_at_end
2729 (const size_type n, const InsertionProxy insert_range_proxy, AllocVersion)
2730 {
2731 return this->priv_forward_range_insert(this->back_ptr(), n, insert_range_proxy);
2732 }
2733
2734 //Takes the range pointed by [first_pos, last_pos) and shifts it to the right
2735 //by 'shift_count'. 'limit_pos' marks the end of constructed elements.
2736 //
2737 //Precondition: first_pos <= last_pos <= limit_pos
2738 //
2739 //The shift operation might cross limit_pos so elements to moved beyond limit_pos
2740 //are uninitialized_moved with an allocator. Other elements are moved.
2741 //
2742 //The shift operation might left uninitialized elements after limit_pos
2743 //and the number of uninitialized elements is returned by the function.
2744 //
2745 //Old situation:
2746 // first_pos last_pos old_limit
2747 // | | |
2748 // ____________V_______V__________________V_____________
2749 //| prefix | range | suffix |raw_mem ~
2750 //|____________|_______|__________________|_____________~
2751 //
2752 //New situation in Case A (hole_size == 0):
2753 // range is moved through move assignments
2754 //
2755 // first_pos last_pos limit_pos
2756 // | | |
2757 // ____________V_______V__________________V_____________
2758 //| prefix' | | | range |suffix'|raw_mem ~
2759 //|________________+______|___^___|_______|_____________~
2760 // | |
2761 // |_>_>_>_>_>^
2762 //
2763 //
2764 //New situation in Case B (hole_size >= 0):
2765 // range is moved through uninitialized moves
2766 //
2767 // first_pos last_pos limit_pos
2768 // | | |
2769 // ____________V_______V__________________V________________
2770 //| prefix' | | | [hole] | range |
2771 //|_______________________________________|________|___^___|
2772 // | |
2773 // |_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_>_^
2774 //
2775 //New situation in Case C (hole_size == 0):
2776 // range is moved through move assignments and uninitialized moves
2777 //
2778 // first_pos last_pos limit_pos
2779 // | | |
2780 // ____________V_______V__________________V___
2781 //| prefix' | | | range |
2782 //|___________________________________|___^___|
2783 // | |
2784 // |_>_>_>_>_>_>_>_>_>_>_>^
2785 size_type priv_insert_ordered_at_shift_range
2786 (size_type first_pos, size_type last_pos, size_type limit_pos, size_type shift_count)
2787 {
2788 BOOST_ASSERT(first_pos <= last_pos);
2789 BOOST_ASSERT(last_pos <= limit_pos);
2790 //
2791 T* const begin_ptr = this->priv_raw_begin();
2792 T* const first_ptr = begin_ptr + first_pos;
2793 T* const last_ptr = begin_ptr + last_pos;
2794
2795 size_type hole_size = 0;
2796 //Case A:
2797 if((last_pos + shift_count) <= limit_pos){
2798 //All move assigned
2799 boost::container::move_backward(first_ptr, last_ptr, last_ptr + shift_count);
2800 }
2801 //Case B:
2802 else if((first_pos + shift_count) >= limit_pos){
2803 //All uninitialized_moved
2804 ::boost::container::uninitialized_move_alloc
2805 (this->m_holder.alloc(), first_ptr, last_ptr, first_ptr + shift_count);
2806 hole_size = first_pos + shift_count - limit_pos;
2807 }
2808 //Case C:
2809 else{
2810 //Some uninitialized_moved
2811 T* const limit_ptr = begin_ptr + limit_pos;
2812 T* const boundary_ptr = limit_ptr - shift_count;
2813 ::boost::container::uninitialized_move_alloc(this->m_holder.alloc(), boundary_ptr, last_ptr, limit_ptr);
2814 //The rest is move assigned
2815 boost::container::move_backward(first_ptr, boundary_ptr, limit_ptr);
2816 }
2817 return hole_size;
2818 }
2819
2820 private:
2821 BOOST_CONTAINER_FORCEINLINE T *priv_raw_begin() const
2822 { return boost::movelib::to_raw_pointer(m_holder.start()); }
2823
2824 BOOST_CONTAINER_FORCEINLINE T* priv_raw_end() const
2825 { return this->priv_raw_begin() + this->m_holder.m_size; }
2826
2827 template <class InsertionProxy>
2828 void priv_forward_range_insert_at_end_expand_forward(const size_type n, InsertionProxy insert_range_proxy)
2829 {
2830 T* const old_finish = this->priv_raw_end();
2831 insert_range_proxy.uninitialized_copy_n_and_update(this->m_holder.alloc(), old_finish, n);
2832 this->m_holder.m_size += n;
2833 }
2834
2835 template <class InsertionProxy>
2836 void priv_forward_range_insert_expand_forward(T* const pos, const size_type n, InsertionProxy insert_range_proxy)
2837 {
2838 //n can't be 0, because there is nothing to do in that case
2839 if(BOOST_UNLIKELY(!n)) return;
2840 //There is enough memory
2841 T* const old_finish = this->priv_raw_end();
2842 const size_type elems_after = old_finish - pos;
2843
2844 if (!elems_after){
2845 insert_range_proxy.uninitialized_copy_n_and_update(this->m_holder.alloc(), old_finish, n);
2846 this->m_holder.m_size += n;
2847 }
2848 else if (elems_after >= n){
2849 //New elements can be just copied.
2850 //Move to uninitialized memory last objects
2851 ::boost::container::uninitialized_move_alloc
2852 (this->m_holder.alloc(), old_finish - n, old_finish, old_finish);
2853 this->m_holder.m_size += n;
2854 //Copy previous to last objects to the initialized end
2855 boost::container::move_backward(pos, old_finish - n, old_finish);
2856 //Insert new objects in the pos
2857 insert_range_proxy.copy_n_and_update(this->m_holder.alloc(), pos, n);
2858 }
2859 else {
2860 //The new elements don't fit in the [pos, end()) range.
2861
2862 //Copy old [pos, end()) elements to the uninitialized memory (a gap is created)
2863 ::boost::container::uninitialized_move_alloc(this->m_holder.alloc(), pos, old_finish, pos + n);
2864 BOOST_TRY{
2865 //Copy first new elements in pos (gap is still there)
2866 insert_range_proxy.copy_n_and_update(this->m_holder.alloc(), pos, elems_after);
2867 //Copy to the beginning of the unallocated zone the last new elements (the gap is closed).
2868 insert_range_proxy.uninitialized_copy_n_and_update(this->m_holder.alloc(), old_finish, n - elems_after);
2869 this->m_holder.m_size += n;
2870 }
2871 BOOST_CATCH(...){
2872 boost::container::destroy_alloc_n(this->get_stored_allocator(), pos + n, elems_after);
2873 BOOST_RETHROW
2874 }
2875 BOOST_CATCH_END
2876 }
2877 }
2878
2879 template <class InsertionProxy>
2880 void priv_forward_range_insert_new_allocation
2881 (T* const new_start, size_type new_cap, T* const pos, const size_type n, InsertionProxy insert_range_proxy)
2882 {
2883 //n can be zero, if we want to reallocate!
2884 T *new_finish = new_start;
2885 T *old_finish;
2886 //Anti-exception rollbacks
2887 typename value_traits::ArrayDeallocator new_buffer_deallocator(new_start, this->m_holder.alloc(), new_cap);
2888 typename value_traits::ArrayDestructor new_values_destroyer(new_start, this->m_holder.alloc(), 0u);
2889
2890 //Initialize with [begin(), pos) old buffer
2891 //the start of the new buffer
2892 T * const old_buffer = this->priv_raw_begin();
2893 if(old_buffer){
2894 new_finish = ::boost::container::uninitialized_move_alloc
2895 (this->m_holder.alloc(), this->priv_raw_begin(), pos, old_finish = new_finish);
2896 new_values_destroyer.increment_size(new_finish - old_finish);
2897 }
2898 //Initialize new objects, starting from previous point
2899 old_finish = new_finish;
2900 insert_range_proxy.uninitialized_copy_n_and_update(this->m_holder.alloc(), old_finish, n);
2901 new_finish += n;
2902 new_values_destroyer.increment_size(new_finish - old_finish);
2903 //Initialize from the rest of the old buffer,
2904 //starting from previous point
2905 if(old_buffer){
2906 new_finish = ::boost::container::uninitialized_move_alloc
2907 (this->m_holder.alloc(), pos, old_buffer + this->m_holder.m_size, new_finish);
2908 //Destroy and deallocate old elements
2909 //If there is allocated memory, destroy and deallocate
2910 if(!value_traits::trivial_dctr_after_move)
2911 boost::container::destroy_alloc_n(this->get_stored_allocator(), old_buffer, this->m_holder.m_size);
2912 allocator_traits_type::deallocate(this->m_holder.alloc(), this->m_holder.start(), this->m_holder.capacity());
2913 }
2914 this->m_holder.start(new_start);
2915 this->m_holder.m_size = new_finish - new_start;
2916 this->m_holder.capacity(new_cap);
2917 //All construction successful, disable rollbacks
2918 new_values_destroyer.release();
2919 new_buffer_deallocator.release();
2920 }
2921
2922 template <class InsertionProxy>
2923 void priv_forward_range_insert_expand_backwards
2924 (T* const new_start, const size_type new_capacity,
2925 T* const pos, const size_type n, InsertionProxy insert_range_proxy)
2926 {
2927 //n can be zero to just expand capacity
2928 //Backup old data
2929 T* const old_start = this->priv_raw_begin();
2930 const size_type old_size = this->m_holder.m_size;
2931 T* const old_finish = old_start + old_size;
2932
2933 //We can have 8 possibilities:
2934 const size_type elemsbefore = static_cast<size_type>(pos - old_start);
2935 const size_type s_before = static_cast<size_type>(old_start - new_start);
2936 const size_type before_plus_new = elemsbefore + n;
2937
2938 //Update the vector buffer information to a safe state
2939 this->m_holder.start(new_start);
2940 this->m_holder.capacity(new_capacity);
2941 this->m_holder.m_size = 0;
2942
2943 //If anything goes wrong, this object will destroy
2944 //all the old objects to fulfill previous vector state
2945 typename value_traits::ArrayDestructor old_values_destroyer(old_start, this->m_holder.alloc(), old_size);
2946 //Check if s_before is big enough to hold the beginning of old data + new data
2947 if(s_before >= before_plus_new){
2948 //Copy first old values before pos, after that the new objects
2949 T *const new_elem_pos =
2950 ::boost::container::uninitialized_move_alloc(this->m_holder.alloc(), old_start, pos, new_start);
2951 this->m_holder.m_size = elemsbefore;
2952 insert_range_proxy.uninitialized_copy_n_and_update(this->m_holder.alloc(), new_elem_pos, n);
2953 this->m_holder.m_size = before_plus_new;
2954 const size_type new_size = old_size + n;
2955 //Check if s_before is so big that even copying the old data + new data
2956 //there is a gap between the new data and the old data
2957 if(s_before >= new_size){
2958 //Old situation:
2959 // _________________________________________________________
2960 //| raw_mem | old_begin | old_end |
2961 //| __________________________________|___________|_________|
2962 //
2963 //New situation:
2964 // _________________________________________________________
2965 //| old_begin | new | old_end | raw_mem |
2966 //|___________|__________|_________|________________________|
2967 //
2968 //Now initialize the rest of memory with the last old values
2969 if(before_plus_new != new_size){ //Special case to avoid operations in back insertion
2970 ::boost::container::uninitialized_move_alloc
2971 (this->m_holder.alloc(), pos, old_finish, new_start + before_plus_new);
2972 //All new elements correctly constructed, avoid new element destruction
2973 this->m_holder.m_size = new_size;
2974 }
2975 //Old values destroyed automatically with "old_values_destroyer"
2976 //when "old_values_destroyer" goes out of scope unless the have trivial
2977 //destructor after move.
2978 if(value_traits::trivial_dctr_after_move)
2979 old_values_destroyer.release();
2980 }
2981 //s_before is so big that divides old_end
2982 else{
2983 //Old situation:
2984 // __________________________________________________
2985 //| raw_mem | old_begin | old_end |
2986 //| ___________________________|___________|_________|
2987 //
2988 //New situation:
2989 // __________________________________________________
2990 //| old_begin | new | old_end | raw_mem |
2991 //|___________|__________|_________|_________________|
2992 //
2993 //Now initialize the rest of memory with the last old values
2994 //All new elements correctly constructed, avoid new element destruction
2995 const size_type raw_gap = s_before - before_plus_new;
2996 if(!value_traits::trivial_dctr){
2997 //Now initialize the rest of s_before memory with the
2998 //first of elements after new values
2999 ::boost::container::uninitialized_move_alloc_n
3000 (this->m_holder.alloc(), pos, raw_gap, new_start + before_plus_new);
3001 //Now we have a contiguous buffer so program trailing element destruction
3002 //and update size to the final size.
3003 old_values_destroyer.shrink_forward(new_size-s_before);
3004 this->m_holder.m_size = new_size;
3005 //Now move remaining last objects in the old buffer begin
3006 T * const remaining_pos = pos + raw_gap;
3007 if(remaining_pos != old_start){ //Make sure data has to be moved
3008 ::boost::container::move(remaining_pos, old_finish, old_start);
3009 }
3010 //Once moved, avoid calling the destructors if trivial after move
3011 if(value_traits::trivial_dctr_after_move){
3012 old_values_destroyer.release();
3013 }
3014 }
3015 else{ //If trivial destructor, we can uninitialized copy + copy in a single uninitialized copy
3016 ::boost::container::uninitialized_move_alloc_n
3017 (this->m_holder.alloc(), pos, static_cast<size_type>(old_finish - pos), new_start + before_plus_new);
3018 this->m_holder.m_size = new_size;
3019 old_values_destroyer.release();
3020 }
3021 }
3022 }
3023 else{
3024 //Check if we have to do the insertion in two phases
3025 //since maybe s_before is not big enough and
3026 //the buffer was expanded both sides
3027 //
3028 //Old situation:
3029 // _________________________________________________
3030 //| raw_mem | old_begin + old_end | raw_mem |
3031 //|_________|_____________________|_________________|
3032 //
3033 //New situation with do_after:
3034 // _________________________________________________
3035 //| old_begin + new + old_end | raw_mem |
3036 //|___________________________________|_____________|
3037 //
3038 //New without do_after:
3039 // _________________________________________________
3040 //| old_begin + new + old_end | raw_mem |
3041 //|____________________________|____________________|
3042 //
3043 const bool do_after = n > s_before;
3044
3045 //Now we can have two situations: the raw_mem of the
3046 //beginning divides the old_begin, or the new elements:
3047 if (s_before <= elemsbefore) {
3048 //The raw memory divides the old_begin group:
3049 //
3050 //If we need two phase construction (do_after)
3051 //new group is divided in new = new_beg + new_end groups
3052 //In this phase only new_beg will be inserted
3053 //
3054 //Old situation:
3055 // _________________________________________________
3056 //| raw_mem | old_begin | old_end | raw_mem |
3057 //|_________|___________|_________|_________________|
3058 //
3059 //New situation with do_after(1):
3060 //This is not definitive situation, the second phase
3061 //will include
3062 // _________________________________________________
3063 //| old_begin | new_beg | old_end | raw_mem |
3064 //|___________|_________|_________|_________________|
3065 //
3066 //New situation without do_after:
3067 // _________________________________________________
3068 //| old_begin | new | old_end | raw_mem |
3069 //|___________|_____|_________|_____________________|
3070 //
3071 //Copy the first part of old_begin to raw_mem
3072 ::boost::container::uninitialized_move_alloc_n
3073 (this->m_holder.alloc(), old_start, s_before, new_start);
3074 //The buffer is all constructed until old_end,
3075 //so program trailing destruction and assign final size
3076 //if !do_after, s_before+n otherwise.
3077 size_type new_1st_range;
3078 if(do_after){
3079 new_1st_range = s_before;
3080 //release destroyer and update size
3081 old_values_destroyer.release();
3082 }
3083 else{
3084 new_1st_range = n;
3085 if(value_traits::trivial_dctr_after_move)
3086 old_values_destroyer.release();
3087 else{
3088 old_values_destroyer.shrink_forward(old_size - (s_before - n));
3089 }
3090 }
3091 this->m_holder.m_size = old_size + new_1st_range;
3092 //Now copy the second part of old_begin overwriting itself
3093 T *const next = ::boost::container::move(old_start + s_before, pos, old_start);
3094 //Now copy the new_beg elements
3095 insert_range_proxy.copy_n_and_update(this->m_holder.alloc(), next, new_1st_range);
3096
3097 //If there is no after work and the last old part needs to be moved to front, do it
3098 if(!do_after && (n != s_before)){
3099 //Now displace old_end elements
3100 ::boost::container::move(pos, old_finish, next + new_1st_range);
3101 }
3102 }
3103 else {
3104 //If we have to expand both sides,
3105 //we will play if the first new values so
3106 //calculate the upper bound of new values
3107
3108 //The raw memory divides the new elements
3109 //
3110 //If we need two phase construction (do_after)
3111 //new group is divided in new = new_beg + new_end groups
3112 //In this phase only new_beg will be inserted
3113 //
3114 //Old situation:
3115 // _______________________________________________________
3116 //| raw_mem | old_begin | old_end | raw_mem |
3117 //|_______________|___________|_________|_________________|
3118 //
3119 //New situation with do_after():
3120 // ____________________________________________________
3121 //| old_begin | new_beg | old_end | raw_mem |
3122 //|___________|_______________|_________|______________|
3123 //
3124 //New situation without do_after:
3125 // ______________________________________________________
3126 //| old_begin | new | old_end | raw_mem |
3127 //|___________|_____|_________|__________________________|
3128 //
3129 //First copy whole old_begin and part of new to raw_mem
3130 T * const new_pos = ::boost::container::uninitialized_move_alloc
3131 (this->m_holder.alloc(), old_start, pos, new_start);
3132 this->m_holder.m_size = elemsbefore;
3133 const size_type mid_n = s_before - elemsbefore;
3134 insert_range_proxy.uninitialized_copy_n_and_update(this->m_holder.alloc(), new_pos, mid_n);
3135 //The buffer is all constructed until old_end,
3136 //release destroyer
3137 this->m_holder.m_size = old_size + s_before;
3138 old_values_destroyer.release();
3139
3140 if(do_after){
3141 //Copy new_beg part
3142 insert_range_proxy.copy_n_and_update(this->m_holder.alloc(), old_start, elemsbefore);
3143 }
3144 else{
3145 //Copy all new elements
3146 const size_type rest_new = n - mid_n;
3147 insert_range_proxy.copy_n_and_update(this->m_holder.alloc(), old_start, rest_new);
3148 T* const move_start = old_start + rest_new;
3149 //Displace old_end, but make sure data has to be moved
3150 T* const move_end = move_start != pos ? ::boost::container::move(pos, old_finish, move_start)
3151 : old_finish;
3152 //Destroy remaining moved elements from old_end except if they
3153 //have trivial destructor after being moved
3154 size_type n_destroy = s_before - n;
3155 if(!value_traits::trivial_dctr_after_move)
3156 boost::container::destroy_alloc_n(this->get_stored_allocator(), move_end, n_destroy);
3157 this->m_holder.m_size -= n_destroy;
3158 }
3159 }
3160
3161 //This is only executed if two phase construction is needed
3162 if(do_after){
3163 //The raw memory divides the new elements
3164 //
3165 //Old situation:
3166 // ______________________________________________________
3167 //| raw_mem | old_begin | old_end | raw_mem |
3168 //|______________|___________|____________|______________|
3169 //
3170 //New situation with do_after(1):
3171 // _______________________________________________________
3172 //| old_begin + new_beg | new_end |old_end | raw_mem |
3173 //|__________________________|_________|________|_________|
3174 //
3175 //New situation with do_after(2):
3176 // ______________________________________________________
3177 //| old_begin + new | old_end |raw |
3178 //|_______________________________________|_________|____|
3179 //
3180 const size_type n_after = n - s_before;
3181 const size_type elemsafter = old_size - elemsbefore;
3182
3183 //We can have two situations:
3184 if (elemsafter >= n_after){
3185 //The raw_mem from end will divide displaced old_end
3186 //
3187 //Old situation:
3188 // ______________________________________________________
3189 //| raw_mem | old_begin | old_end | raw_mem |
3190 //|______________|___________|____________|______________|
3191 //
3192 //New situation with do_after(1):
3193 // _______________________________________________________
3194 //| old_begin + new_beg | new_end |old_end | raw_mem |
3195 //|__________________________|_________|________|_________|
3196 //
3197 //First copy the part of old_end raw_mem
3198 T* finish_n = old_finish - n_after;
3199 ::boost::container::uninitialized_move_alloc
3200 (this->m_holder.alloc(), finish_n, old_finish, old_finish);
3201 this->m_holder.m_size += n_after;
3202 //Displace the rest of old_end to the new position
3203 boost::container::move_backward(pos, finish_n, old_finish);
3204 //Now overwrite with new_end
3205 //The new_end part is [first + (n - n_after), last)
3206 insert_range_proxy.copy_n_and_update(this->m_holder.alloc(), pos, n_after);
3207 }
3208 else {
3209 //The raw_mem from end will divide new_end part
3210 //
3211 //Old situation:
3212 // _____________________________________________________________
3213 //| raw_mem | old_begin | old_end | raw_mem |
3214 //|______________|___________|____________|_____________________|
3215 //
3216 //New situation with do_after(2):
3217 // _____________________________________________________________
3218 //| old_begin + new_beg | new_end |old_end | raw_mem |
3219 //|__________________________|_______________|________|_________|
3220 //
3221
3222 const size_type mid_last_dist = n_after - elemsafter;
3223 //First initialize data in raw memory
3224
3225 //Copy to the old_end part to the uninitialized zone leaving a gap.
3226 ::boost::container::uninitialized_move_alloc
3227 (this->m_holder.alloc(), pos, old_finish, old_finish + mid_last_dist);
3228
3229 typename value_traits::ArrayDestructor old_end_destroyer
3230 (old_finish + mid_last_dist, this->m_holder.alloc(), old_finish - pos);
3231
3232 //Copy the first part to the already constructed old_end zone
3233 insert_range_proxy.copy_n_and_update(this->m_holder.alloc(), pos, elemsafter);
3234 //Copy the rest to the uninitialized zone filling the gap
3235 insert_range_proxy.uninitialized_copy_n_and_update(this->m_holder.alloc(), old_finish, mid_last_dist);
3236 this->m_holder.m_size += n_after;
3237 old_end_destroyer.release();
3238 }
3239 }
3240 }
3241 }
3242
3243 void priv_throw_if_out_of_range(size_type n) const
3244 {
3245 //If n is out of range, throw an out_of_range exception
3246 if (n >= this->size()){
3247 throw_out_of_range("vector::at out of range");
3248 }
3249 }
3250
3251 bool priv_in_range(const_iterator pos) const
3252 {
3253 return (this->begin() <= pos) && (pos < this->end());
3254 }
3255
3256 bool priv_in_range_or_end(const_iterator pos) const
3257 {
3258 return (this->begin() <= pos) && (pos <= this->end());
3259 }
3260
3261 #ifdef BOOST_CONTAINER_VECTOR_ALLOC_STATS
3262 public:
3263 unsigned int num_expand_fwd;
3264 unsigned int num_expand_bwd;
3265 unsigned int num_shrink;
3266 unsigned int num_alloc;
3267 void reset_alloc_stats()
3268 { num_expand_fwd = num_expand_bwd = num_alloc = 0, num_shrink = 0; }
3269 #endif
3270 #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
3271 };
3272
3273 }} //namespace boost::container
3274
3275 #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
3276
3277 namespace boost {
3278
3279 //!has_trivial_destructor_after_move<> == true_type
3280 //!specialization for optimizations
3281 template <class T, class Allocator>
3282 struct has_trivial_destructor_after_move<boost::container::vector<T, Allocator> >
3283 {
3284 typedef typename ::boost::container::allocator_traits<Allocator>::pointer pointer;
3285 static const bool value = ::boost::has_trivial_destructor_after_move<Allocator>::value &&
3286 ::boost::has_trivial_destructor_after_move<pointer>::value;
3287 };
3288
3289 }
3290
3291 #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
3292
3293 #include <boost/container/detail/config_end.hpp>
3294
3295 #endif // #ifndef BOOST_CONTAINER_CONTAINER_VECTOR_HPP