fix doc example typo
[boost.git] / boost / interprocess / containers / container / deque.hpp
blob0963e1831a93a252c86d692cb70c9cd5eb7f7b81
1 /*
3 * Copyright (c) 1994
4 * Hewlett-Packard Company
6 * Permission to use, copy, modify, distribute and sell this software
7 * and its documentation for any purpose is hereby granted without fee,
8 * provided that the above copyright notice appear in all copies and
9 * that both that copyright notice and this permission notice appear
10 * in supporting documentation. Hewlett-Packard Company makes no
11 * representations about the suitability of this software for any
12 * purpose. It is provided "as is" without express or implied warranty.
15 * Copyright (c) 1996
16 * Silicon Graphics Computer Systems, Inc.
18 * Permission to use, copy, modify, distribute and sell this software
19 * and its documentation for any purpose is hereby granted without fee,
20 * provided that the above copyright notice appear in all copies and
21 * that both that copyright notice and this permission notice appear
22 * in supporting documentation. Silicon Graphics makes no
23 * representations about the suitability of this software for any
24 * purpose. It is provided "as is" without express or implied warranty.
27 //////////////////////////////////////////////////////////////////////////////
29 // (C) Copyright Ion Gaztanaga 2005-2006. Distributed under the Boost
30 // Software License, Version 1.0. (See accompanying file
31 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
33 // See http://www.boost.org/libs/container for documentation.
35 //////////////////////////////////////////////////////////////////////////////
37 // This file comes from SGI's stl_deque.h and stl_uninitialized.h files.
38 // Modified by Ion Gaztanaga 2005.
39 // Renaming, isolating and porting to generic algorithms. Pointer typedef
40 // set to allocator::pointer to allow placing it in shared memory.
42 ///////////////////////////////////////////////////////////////////////////////
44 #ifndef BOOST_CONTAINERS_DEQUE_HPP
45 #define BOOST_CONTAINERS_DEQUE_HPP
47 #if (defined _MSC_VER) && (_MSC_VER >= 1200)
48 # pragma once
49 #endif
51 #include <boost/interprocess/containers/container/detail/config_begin.hpp>
52 #include <boost/interprocess/containers/container/detail/workaround.hpp>
54 #include <boost/interprocess/containers/container/detail/utilities.hpp>
55 #include <boost/interprocess/containers/container/detail/iterators.hpp>
56 #include <boost/interprocess/containers/container/detail/algorithms.hpp>
57 #include <boost/interprocess/containers/container/detail/mpl.hpp>
58 #include <boost/interprocess/containers/container/containers_fwd.hpp>
59 #include <cstddef>
60 #include <iterator>
61 #include <cassert>
62 #include <memory>
63 #include <algorithm>
64 #include <stdexcept>
65 #include <boost/detail/no_exceptions_support.hpp>
66 #include <boost/type_traits/has_trivial_destructor.hpp>
67 #include <boost/type_traits/has_trivial_copy.hpp>
68 #include <boost/type_traits/has_trivial_assign.hpp>
69 #include <boost/type_traits/has_nothrow_copy.hpp>
70 #include <boost/type_traits/has_nothrow_assign.hpp>
71 #include <boost/interprocess/detail/move.hpp>
72 #include <boost/interprocess/containers/container/detail/advanced_insert_int.hpp>
74 #ifdef BOOST_INTERPROCESS_DOXYGEN_INVOKED
75 namespace boost {
76 namespace interprocess {
77 #else
78 namespace boost {
79 namespace interprocess_container {
80 #endif
82 /// @cond
83 template <class T, class Alloc>
84 class deque;
86 template <class T, class A>
87 struct deque_value_traits
89 typedef T value_type;
90 typedef A allocator_type;
91 static const bool trivial_dctr = boost::has_trivial_destructor<value_type>::value;
92 static const bool trivial_dctr_after_move =
93 boost::interprocess::has_trivial_destructor_after_move<value_type>::value || trivial_dctr;
94 static const bool trivial_copy = has_trivial_copy<value_type>::value;
95 static const bool nothrow_copy = has_nothrow_copy<value_type>::value;
96 static const bool trivial_assign = has_trivial_assign<value_type>::value;
97 static const bool nothrow_assign = has_nothrow_assign<value_type>::value;
101 // Note: this function is simply a kludge to work around several compilers'
102 // bugs in handling constant expressions.
103 inline std::size_t deque_buf_size(std::size_t size)
104 { return size < 512 ? std::size_t(512 / size) : std::size_t(1); }
106 // Deque base class. It has two purposes. First, its constructor
107 // and destructor allocate (but don't initialize) storage. This makes
108 // exception safety easier.
109 template <class T, class Alloc>
110 class deque_base
112 public:
113 typedef typename Alloc::value_type val_alloc_val;
114 typedef typename Alloc::pointer val_alloc_ptr;
115 typedef typename Alloc::const_pointer val_alloc_cptr;
116 typedef typename Alloc::reference val_alloc_ref;
117 typedef typename Alloc::const_reference val_alloc_cref;
118 typedef typename Alloc::value_type val_alloc_diff;
119 typedef typename Alloc::template rebind
120 <typename Alloc::pointer>::other ptr_alloc_t;
121 typedef typename ptr_alloc_t::value_type ptr_alloc_val;
122 typedef typename ptr_alloc_t::pointer ptr_alloc_ptr;
123 typedef typename ptr_alloc_t::const_pointer ptr_alloc_cptr;
124 typedef typename ptr_alloc_t::reference ptr_alloc_ref;
125 typedef typename ptr_alloc_t::const_reference ptr_alloc_cref;
126 typedef typename Alloc::template
127 rebind<T>::other allocator_type;
128 typedef allocator_type stored_allocator_type;
130 protected:
132 typedef deque_value_traits<T, Alloc> traits_t;
133 typedef typename Alloc::template
134 rebind<typename Alloc::pointer>::other map_allocator_type;
136 static std::size_t s_buffer_size() { return deque_buf_size(sizeof(T)); }
138 val_alloc_ptr priv_allocate_node()
139 { return this->alloc().allocate(s_buffer_size()); }
141 void priv_deallocate_node(val_alloc_ptr p)
142 { this->alloc().deallocate(p, s_buffer_size()); }
144 ptr_alloc_ptr priv_allocate_map(std::size_t n)
145 { return this->ptr_alloc().allocate(n); }
147 void priv_deallocate_map(ptr_alloc_ptr p, std::size_t n)
148 { this->ptr_alloc().deallocate(p, n); }
150 public:
151 // Class invariants:
152 // For any nonsingular iterator i:
153 // i.node is the address of an element in the map array. The
154 // contents of i.node is a pointer to the beginning of a node.
155 // i.first == //(i.node)
156 // i.last == i.first + node_size
157 // i.cur is a pointer in the range [i.first, i.last). NOTE:
158 // the implication of this is that i.cur is always a dereferenceable
159 // pointer, even if i is a past-the-end iterator.
160 // Start and Finish are always nonsingular iterators. NOTE: this means
161 // that an empty deque must have one node, and that a deque
162 // with N elements, where N is the buffer size, must have two nodes.
163 // For every node other than start.node and finish.node, every element
164 // in the node is an initialized object. If start.node == finish.node,
165 // then [start.cur, finish.cur) are initialized objects, and
166 // the elements outside that range are uninitialized storage. Otherwise,
167 // [start.cur, start.last) and [finish.first, finish.cur) are initialized
168 // objects, and [start.first, start.cur) and [finish.cur, finish.last)
169 // are uninitialized storage.
170 // [map, map + map_size) is a valid, non-empty range.
171 // [start.node, finish.node] is a valid range contained within
172 // [map, map + map_size).
173 // A pointer in the range [map, map + map_size) points to an allocated node
174 // if and only if the pointer is in the range [start.node, finish.node].
175 class const_iterator
176 : public std::iterator<std::random_access_iterator_tag,
177 val_alloc_val, val_alloc_diff,
178 val_alloc_cptr, val_alloc_cref>
180 public:
181 static std::size_t s_buffer_size() { return deque_base<T, Alloc>::s_buffer_size(); }
183 typedef std::random_access_iterator_tag iterator_category;
184 typedef val_alloc_val value_type;
185 typedef val_alloc_cptr pointer;
186 typedef val_alloc_cref reference;
187 typedef std::size_t size_type;
188 typedef std::ptrdiff_t difference_type;
190 typedef ptr_alloc_ptr index_pointer;
191 typedef const_iterator self_t;
193 friend class deque<T, Alloc>;
194 friend class deque_base<T, Alloc>;
196 protected:
197 val_alloc_ptr m_cur;
198 val_alloc_ptr m_first;
199 val_alloc_ptr m_last;
200 index_pointer m_node;
202 public:
203 const_iterator(val_alloc_ptr x, index_pointer y)
204 : m_cur(x), m_first(*y),
205 m_last(*y + s_buffer_size()), m_node(y) {}
207 const_iterator() : m_cur(0), m_first(0), m_last(0), m_node(0) {}
209 const_iterator(const const_iterator& x)
210 : m_cur(x.m_cur), m_first(x.m_first),
211 m_last(x.m_last), m_node(x.m_node) {}
213 reference operator*() const
214 { return *this->m_cur; }
216 pointer operator->() const
217 { return this->m_cur; }
219 difference_type operator-(const self_t& x) const
221 if(!this->m_cur && !x.m_cur){
222 return 0;
224 return difference_type(this->s_buffer_size()) * (this->m_node - x.m_node - 1) +
225 (this->m_cur - this->m_first) + (x.m_last - x.m_cur);
228 self_t& operator++()
230 ++this->m_cur;
231 if (this->m_cur == this->m_last) {
232 this->priv_set_node(this->m_node + 1);
233 this->m_cur = this->m_first;
235 return *this;
238 self_t operator++(int)
240 self_t tmp = *this;
241 ++*this;
242 return tmp;
245 self_t& operator--()
247 if (this->m_cur == this->m_first) {
248 this->priv_set_node(this->m_node - 1);
249 this->m_cur = this->m_last;
251 --this->m_cur;
252 return *this;
255 self_t operator--(int)
257 self_t tmp = *this;
258 --*this;
259 return tmp;
262 self_t& operator+=(difference_type n)
264 difference_type offset = n + (this->m_cur - this->m_first);
265 if (offset >= 0 && offset < difference_type(this->s_buffer_size()))
266 this->m_cur += n;
267 else {
268 difference_type node_offset =
269 offset > 0 ? offset / difference_type(this->s_buffer_size())
270 : -difference_type((-offset - 1) / this->s_buffer_size()) - 1;
271 this->priv_set_node(this->m_node + node_offset);
272 this->m_cur = this->m_first +
273 (offset - node_offset * difference_type(this->s_buffer_size()));
275 return *this;
278 self_t operator+(difference_type n) const
279 { self_t tmp = *this; return tmp += n; }
281 self_t& operator-=(difference_type n)
282 { return *this += -n; }
284 self_t operator-(difference_type n) const
285 { self_t tmp = *this; return tmp -= n; }
287 reference operator[](difference_type n) const
288 { return *(*this + n); }
290 bool operator==(const self_t& x) const
291 { return this->m_cur == x.m_cur; }
293 bool operator!=(const self_t& x) const
294 { return !(*this == x); }
296 bool operator<(const self_t& x) const
298 return (this->m_node == x.m_node) ?
299 (this->m_cur < x.m_cur) : (this->m_node < x.m_node);
302 bool operator>(const self_t& x) const
303 { return x < *this; }
305 bool operator<=(const self_t& x) const
306 { return !(x < *this); }
308 bool operator>=(const self_t& x) const
309 { return !(*this < x); }
311 void priv_set_node(index_pointer new_node)
313 this->m_node = new_node;
314 this->m_first = *new_node;
315 this->m_last = this->m_first + difference_type(this->s_buffer_size());
318 friend const_iterator operator+(std::ptrdiff_t n, const const_iterator& x)
319 { return x + n; }
322 //Deque iterator
323 class iterator : public const_iterator
325 public:
326 typedef std::random_access_iterator_tag iterator_category;
327 typedef val_alloc_val value_type;
328 typedef val_alloc_ptr pointer;
329 typedef val_alloc_ref reference;
330 typedef std::size_t size_type;
331 typedef std::ptrdiff_t difference_type;
332 typedef ptr_alloc_ptr index_pointer;
333 typedef const_iterator self_t;
335 friend class deque<T, Alloc>;
336 friend class deque_base<T, Alloc>;
338 private:
339 explicit iterator(const const_iterator& x) : const_iterator(x){}
341 public:
342 //Constructors
343 iterator(val_alloc_ptr x, index_pointer y) : const_iterator(x, y){}
344 iterator() : const_iterator(){}
345 //iterator(const const_iterator &cit) : const_iterator(cit){}
346 iterator(const iterator& x) : const_iterator(x){}
348 //Pointer like operators
349 reference operator*() const { return *this->m_cur; }
350 pointer operator->() const { return this->m_cur; }
352 reference operator[](difference_type n) const { return *(*this + n); }
354 //Increment / Decrement
355 iterator& operator++()
356 { this->const_iterator::operator++(); return *this; }
358 iterator operator++(int)
359 { iterator tmp = *this; ++*this; return tmp; }
361 iterator& operator--()
362 { this->const_iterator::operator--(); return *this; }
364 iterator operator--(int)
365 { iterator tmp = *this; --*this; return tmp; }
367 // Arithmetic
368 iterator& operator+=(difference_type off)
369 { this->const_iterator::operator+=(off); return *this; }
371 iterator operator+(difference_type off) const
372 { return iterator(this->const_iterator::operator+(off)); }
374 friend iterator operator+(difference_type off, const iterator& right)
375 { return iterator(off+static_cast<const const_iterator &>(right)); }
377 iterator& operator-=(difference_type off)
378 { this->const_iterator::operator-=(off); return *this; }
380 iterator operator-(difference_type off) const
381 { return iterator(this->const_iterator::operator-(off)); }
383 difference_type operator-(const const_iterator& right) const
384 { return static_cast<const const_iterator&>(*this) - right; }
387 deque_base(const allocator_type& a, std::size_t num_elements)
388 : members_(a)
389 { this->priv_initialize_map(num_elements); }
391 deque_base(const allocator_type& a)
392 : members_(a)
395 ~deque_base()
397 if (this->members_.m_map) {
398 this->priv_destroy_nodes(this->members_.m_start.m_node, this->members_.m_finish.m_node + 1);
399 this->priv_deallocate_map(this->members_.m_map, this->members_.m_map_size);
403 private:
404 deque_base(const deque_base&);
406 protected:
408 void priv_initialize_map(std::size_t num_elements)
410 // if(num_elements){
411 std::size_t num_nodes = num_elements / s_buffer_size() + 1;
413 this->members_.m_map_size = containers_detail::max_value((std::size_t) InitialMapSize, num_nodes + 2);
414 this->members_.m_map = this->priv_allocate_map(this->members_.m_map_size);
416 ptr_alloc_ptr nstart = this->members_.m_map + (this->members_.m_map_size - num_nodes) / 2;
417 ptr_alloc_ptr nfinish = nstart + num_nodes;
419 BOOST_TRY {
420 this->priv_create_nodes(nstart, nfinish);
422 BOOST_CATCH(...){
423 this->priv_deallocate_map(this->members_.m_map, this->members_.m_map_size);
424 this->members_.m_map = 0;
425 this->members_.m_map_size = 0;
426 BOOST_RETHROW
428 BOOST_CATCH_END
430 this->members_.m_start.priv_set_node(nstart);
431 this->members_.m_finish.priv_set_node(nfinish - 1);
432 this->members_.m_start.m_cur = this->members_.m_start.m_first;
433 this->members_.m_finish.m_cur = this->members_.m_finish.m_first +
434 num_elements % s_buffer_size();
435 // }
438 void priv_create_nodes(ptr_alloc_ptr nstart, ptr_alloc_ptr nfinish)
440 ptr_alloc_ptr cur;
441 BOOST_TRY {
442 for (cur = nstart; cur < nfinish; ++cur)
443 *cur = this->priv_allocate_node();
445 BOOST_CATCH(...){
446 this->priv_destroy_nodes(nstart, cur);
447 BOOST_RETHROW
449 BOOST_CATCH_END
452 void priv_destroy_nodes(ptr_alloc_ptr nstart, ptr_alloc_ptr nfinish)
454 for (ptr_alloc_ptr n = nstart; n < nfinish; ++n)
455 this->priv_deallocate_node(*n);
458 enum { InitialMapSize = 8 };
460 protected:
461 struct members_holder
462 : public ptr_alloc_t
463 , public allocator_type
465 members_holder(const allocator_type &a)
466 : map_allocator_type(a), allocator_type(a)
467 , m_map(0), m_map_size(0)
468 , m_start(), m_finish(m_start)
471 ptr_alloc_ptr m_map;
472 std::size_t m_map_size;
473 iterator m_start;
474 iterator m_finish;
475 } members_;
477 ptr_alloc_t &ptr_alloc()
478 { return members_; }
480 const ptr_alloc_t &ptr_alloc() const
481 { return members_; }
483 allocator_type &alloc()
484 { return members_; }
486 const allocator_type &alloc() const
487 { return members_; }
489 /// @endcond
491 //! Deque class
493 template <class T, class Alloc>
494 class deque : protected deque_base<T, Alloc>
496 /// @cond
497 typedef deque_base<T, Alloc> Base;
499 public: // Basic types
500 typedef typename Alloc::value_type val_alloc_val;
501 typedef typename Alloc::pointer val_alloc_ptr;
502 typedef typename Alloc::const_pointer val_alloc_cptr;
503 typedef typename Alloc::reference val_alloc_ref;
504 typedef typename Alloc::const_reference val_alloc_cref;
505 typedef typename Alloc::template
506 rebind<val_alloc_ptr>::other ptr_alloc_t;
507 typedef typename ptr_alloc_t::value_type ptr_alloc_val;
508 typedef typename ptr_alloc_t::pointer ptr_alloc_ptr;
509 typedef typename ptr_alloc_t::const_pointer ptr_alloc_cptr;
510 typedef typename ptr_alloc_t::reference ptr_alloc_ref;
511 typedef typename ptr_alloc_t::const_reference ptr_alloc_cref;
512 /// @endcond
514 typedef T value_type;
515 typedef val_alloc_ptr pointer;
516 typedef val_alloc_cptr const_pointer;
517 typedef val_alloc_ref reference;
518 typedef val_alloc_cref const_reference;
519 typedef std::size_t size_type;
520 typedef std::ptrdiff_t difference_type;
522 typedef typename Base::allocator_type allocator_type;
524 public: // Iterators
525 typedef typename Base::iterator iterator;
526 typedef typename Base::const_iterator const_iterator;
528 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
529 typedef std::reverse_iterator<iterator> reverse_iterator;
531 /// @cond
532 private: // Internal typedefs
533 typedef ptr_alloc_ptr index_pointer;
534 static std::size_t s_buffer_size()
535 { return Base::s_buffer_size(); }
536 typedef containers_detail::advanced_insert_aux_int<value_type, iterator> advanced_insert_aux_int_t;
537 typedef repeat_iterator<T, difference_type> r_iterator;
538 typedef boost::interprocess::move_iterator<r_iterator> move_it;
540 /// @endcond
542 allocator_type get_allocator() const { return Base::alloc(); }
544 public: // Basic accessors
545 BOOST_INTERPROCESS_ENABLE_MOVE_EMULATION(deque)
547 iterator begin()
548 { return this->members_.m_start; }
550 iterator end()
551 { return this->members_.m_finish; }
553 const_iterator begin() const
554 { return this->members_.m_start; }
556 const_iterator end() const
557 { return this->members_.m_finish; }
559 reverse_iterator rbegin()
560 { return reverse_iterator(this->members_.m_finish); }
562 reverse_iterator rend()
563 { return reverse_iterator(this->members_.m_start); }
565 const_reverse_iterator rbegin() const
566 { return const_reverse_iterator(this->members_.m_finish); }
568 const_reverse_iterator rend() const
569 { return const_reverse_iterator(this->members_.m_start); }
571 const_iterator cbegin() const
572 { return this->members_.m_start; }
574 const_iterator cend() const
575 { return this->members_.m_finish; }
577 const_reverse_iterator crbegin() const
578 { return const_reverse_iterator(this->members_.m_finish); }
580 const_reverse_iterator crend() const
581 { return const_reverse_iterator(this->members_.m_start); }
583 reference operator[](size_type n)
584 { return this->members_.m_start[difference_type(n)]; }
586 const_reference operator[](size_type n) const
587 { return this->members_.m_start[difference_type(n)]; }
589 void priv_range_check(size_type n) const
590 { if (n >= this->size()) BOOST_RETHROW std::out_of_range("deque"); }
592 reference at(size_type n)
593 { this->priv_range_check(n); return (*this)[n]; }
595 const_reference at(size_type n) const
596 { this->priv_range_check(n); return (*this)[n]; }
598 reference front() { return *this->members_.m_start; }
600 reference back() { return *(end()-1); }
602 const_reference front() const
603 { return *this->members_.m_start; }
605 const_reference back() const { return *(cend()-1); }
607 size_type size() const
608 { return this->members_.m_finish - this->members_.m_start; }
610 size_type max_size() const
611 { return this->alloc().max_size(); }
613 bool empty() const
614 { return this->members_.m_finish == this->members_.m_start; }
616 explicit deque(const allocator_type& a = allocator_type())
617 : Base(a)
620 deque(const deque& x)
621 : Base(x.alloc())
623 if(x.size()){
624 this->priv_initialize_map(x.size());
625 std::uninitialized_copy(x.begin(), x.end(), this->members_.m_start);
629 deque(BOOST_INTERPROCESS_RV_REF(deque) mx)
630 : Base(mx.alloc())
631 { this->swap(mx); }
633 deque(size_type n, const value_type& value,
634 const allocator_type& a = allocator_type()) : Base(a, n)
635 { this->priv_fill_initialize(value); }
637 explicit deque(size_type n) : Base(allocator_type(), n)
638 { this->resize(n); }
640 // Check whether it's an integral type. If so, it's not an iterator.
641 template <class InpIt>
642 deque(InpIt first, InpIt last, const allocator_type& a = allocator_type())
643 : Base(a)
645 //Dispatch depending on integer/iterator
646 const bool aux_boolean = containers_detail::is_convertible<InpIt, std::size_t>::value;
647 typedef containers_detail::bool_<aux_boolean> Result;
648 this->priv_initialize_dispatch(first, last, Result());
651 ~deque()
653 priv_destroy_range(this->members_.m_start, this->members_.m_finish);
656 deque& operator= (const deque& x)
658 const size_type len = size();
659 if (&x != this) {
660 if (len >= x.size())
661 this->erase(std::copy(x.begin(), x.end(), this->members_.m_start), this->members_.m_finish);
662 else {
663 const_iterator mid = x.begin() + difference_type(len);
664 std::copy(x.begin(), mid, this->members_.m_start);
665 this->insert(this->members_.m_finish, mid, x.end());
668 return *this;
671 deque& operator= (BOOST_INTERPROCESS_RV_REF(deque) x)
673 this->clear();
674 this->swap(x);
675 return *this;
678 void swap(deque &x)
680 std::swap(this->members_.m_start, x.members_.m_start);
681 std::swap(this->members_.m_finish, x.members_.m_finish);
682 std::swap(this->members_.m_map, x.members_.m_map);
683 std::swap(this->members_.m_map_size, x.members_.m_map_size);
686 void assign(size_type n, const T& val)
687 { this->priv_fill_assign(n, val); }
689 template <class InpIt>
690 void assign(InpIt first, InpIt last)
692 //Dispatch depending on integer/iterator
693 const bool aux_boolean = containers_detail::is_convertible<InpIt, std::size_t>::value;
694 typedef containers_detail::bool_<aux_boolean> Result;
695 this->priv_assign_dispatch(first, last, Result());
698 void push_back(const value_type& t)
700 if(this->priv_push_back_simple_available()){
701 new(this->priv_push_back_simple_pos())value_type(t);
702 this->priv_push_back_simple_commit();
704 else{
705 this->priv_insert_aux(cend(), size_type(1), t);
709 void push_back(BOOST_INTERPROCESS_RV_REF(value_type) t)
711 if(this->priv_push_back_simple_available()){
712 new(this->priv_push_back_simple_pos())value_type(boost::interprocess::move(t));
713 this->priv_push_back_simple_commit();
715 else{
716 this->priv_insert_aux(cend(), move_it(r_iterator(t, 1)), move_it(r_iterator()));
720 void push_front(const value_type& t)
722 if(this->priv_push_front_simple_available()){
723 new(this->priv_push_front_simple_pos())value_type(t);
724 this->priv_push_front_simple_commit();
726 else{
727 this->priv_insert_aux(cbegin(), size_type(1), t);
731 void push_front(BOOST_INTERPROCESS_RV_REF(value_type) t)
733 if(this->priv_push_front_simple_available()){
734 new(this->priv_push_front_simple_pos())value_type(boost::interprocess::move(t));
735 this->priv_push_front_simple_commit();
737 else{
738 this->priv_insert_aux(cbegin(), move_it(r_iterator(t, 1)), move_it(r_iterator()));
742 void pop_back()
744 if (this->members_.m_finish.m_cur != this->members_.m_finish.m_first) {
745 --this->members_.m_finish.m_cur;
746 containers_detail::get_pointer(this->members_.m_finish.m_cur)->~value_type();
748 else
749 this->priv_pop_back_aux();
752 void pop_front()
754 if (this->members_.m_start.m_cur != this->members_.m_start.m_last - 1) {
755 containers_detail::get_pointer(this->members_.m_start.m_cur)->~value_type();
756 ++this->members_.m_start.m_cur;
758 else
759 this->priv_pop_front_aux();
762 iterator insert(const_iterator position, const value_type& x)
764 if (position == cbegin()){
765 this->push_front(x);
766 return begin();
768 else if (position == cend()){
769 this->push_back(x);
770 return (end()-1);
772 else {
773 size_type n = position - cbegin();
774 this->priv_insert_aux(position, size_type(1), x);
775 return iterator(this->begin() + n);
779 iterator insert(const_iterator position, BOOST_INTERPROCESS_RV_REF(value_type) mx)
781 if (position == cbegin()) {
782 this->push_front(boost::interprocess::move(mx));
783 return begin();
785 else if (position == cend()) {
786 this->push_back(boost::interprocess::move(mx));
787 return(end()-1);
789 else {
790 //Just call more general insert(pos, size, value) and return iterator
791 size_type n = position - begin();
792 this->priv_insert_aux(position, move_it(r_iterator(mx, 1)), move_it(r_iterator()));
793 return iterator(this->begin() + n);
797 void insert(const_iterator pos, size_type n, const value_type& x)
798 { this->priv_fill_insert(pos, n, x); }
800 // Check whether it's an integral type. If so, it's not an iterator.
801 template <class InpIt>
802 void insert(const_iterator pos, InpIt first, InpIt last)
804 //Dispatch depending on integer/iterator
805 const bool aux_boolean = containers_detail::is_convertible<InpIt, std::size_t>::value;
806 typedef containers_detail::bool_<aux_boolean> Result;
807 this->priv_insert_dispatch(pos, first, last, Result());
810 #if defined(BOOST_CONTAINERS_PERFECT_FORWARDING) || defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
812 template <class... Args>
813 void emplace_back(Args&&... args)
815 if(this->priv_push_back_simple_available()){
816 new(this->priv_push_back_simple_pos())value_type(boost::interprocess::forward<Args>(args)...);
817 this->priv_push_back_simple_commit();
819 else{
820 containers_detail::advanced_insert_aux_emplace<T, iterator, Args...> proxy(boost::interprocess::forward<Args>(args)...);
821 this->priv_insert_aux_impl(this->cend(), 1, proxy);
825 template <class... Args>
826 void emplace_front(Args&&... args)
828 if(this->priv_push_front_simple_available()){
829 new(this->priv_push_front_simple_pos())value_type(boost::interprocess::forward<Args>(args)...);
830 this->priv_push_front_simple_commit();
832 else{
833 containers_detail::advanced_insert_aux_emplace<T, iterator, Args...> proxy(boost::interprocess::forward<Args>(args)...);
834 this->priv_insert_aux_impl(this->cbegin(), 1, proxy);
838 template <class... Args>
839 iterator emplace(const_iterator p, Args&&... args)
841 if(p == this->cbegin()){
842 this->emplace_front(boost::interprocess::forward<Args>(args)...);
843 return this->begin();
845 else if(p == this->cend()){
846 this->emplace_back(boost::interprocess::forward<Args>(args)...);
847 return (this->end()-1);
849 else{
850 size_type n = p - this->cbegin();
851 containers_detail::advanced_insert_aux_emplace<T, iterator, Args...> proxy(boost::interprocess::forward<Args>(args)...);
852 this->priv_insert_aux_impl(p, 1, proxy);
853 return iterator(this->begin() + n);
857 #else //#ifdef BOOST_CONTAINERS_PERFECT_FORWARDING
859 //0 args
860 void emplace_back()
862 if(priv_push_front_simple_available()){
863 new(priv_push_front_simple_pos())value_type();
864 priv_push_front_simple_commit();
866 else{
867 containers_detail::advanced_insert_aux_emplace<T, iterator> proxy;
868 priv_insert_aux_impl(cend(), 1, proxy);
872 void emplace_front()
874 if(priv_push_front_simple_available()){
875 new(priv_push_front_simple_pos())value_type();
876 priv_push_front_simple_commit();
878 else{
879 containers_detail::advanced_insert_aux_emplace<T, iterator> proxy;
880 priv_insert_aux_impl(cbegin(), 1, proxy);
884 iterator emplace(const_iterator p)
886 if(p == cbegin()){
887 emplace_front();
888 return begin();
890 else if(p == cend()){
891 emplace_back();
892 return (end()-1);
894 else{
895 size_type n = p - cbegin();
896 containers_detail::advanced_insert_aux_emplace<T, iterator> proxy;
897 priv_insert_aux_impl(p, 1, proxy);
898 return iterator(this->begin() + n);
902 //advanced_insert_int.hpp includes all necessary preprocessor machinery...
903 #define BOOST_PP_LOCAL_MACRO(n) \
904 template<BOOST_PP_ENUM_PARAMS(n, class P)> \
905 void emplace_back(BOOST_PP_ENUM(n, BOOST_CONTAINERS_PP_PARAM_LIST, _)) \
907 if(priv_push_back_simple_available()){ \
908 new(priv_push_back_simple_pos())value_type \
909 (BOOST_PP_ENUM(n, BOOST_CONTAINERS_PP_PARAM_FORWARD, _)); \
910 priv_push_back_simple_commit(); \
912 else{ \
913 containers_detail::BOOST_PP_CAT(BOOST_PP_CAT(advanced_insert_aux_emplace, n), arg) \
914 <value_type, iterator, BOOST_PP_ENUM_PARAMS(n, P)> \
915 proxy(BOOST_PP_ENUM(n, BOOST_CONTAINERS_PP_PARAM_FORWARD, _)); \
916 priv_insert_aux_impl(cend(), 1, proxy); \
920 template<BOOST_PP_ENUM_PARAMS(n, class P)> \
921 void emplace_front(BOOST_PP_ENUM(n, BOOST_CONTAINERS_PP_PARAM_LIST, _)) \
923 if(priv_push_front_simple_available()){ \
924 new(priv_push_front_simple_pos())value_type \
925 (BOOST_PP_ENUM(n, BOOST_CONTAINERS_PP_PARAM_FORWARD, _)); \
926 priv_push_front_simple_commit(); \
928 else{ \
929 containers_detail::BOOST_PP_CAT(BOOST_PP_CAT(advanced_insert_aux_emplace, n), arg) \
930 <value_type, iterator, BOOST_PP_ENUM_PARAMS(n, P)> \
931 proxy(BOOST_PP_ENUM(n, BOOST_CONTAINERS_PP_PARAM_FORWARD, _)); \
932 priv_insert_aux_impl(cbegin(), 1, proxy); \
936 template<BOOST_PP_ENUM_PARAMS(n, class P)> \
937 iterator emplace(const_iterator p, BOOST_PP_ENUM(n, BOOST_CONTAINERS_PP_PARAM_LIST, _)) \
939 if(p == this->cbegin()){ \
940 this->emplace_front(BOOST_PP_ENUM(n, BOOST_CONTAINERS_PP_PARAM_FORWARD, _)); \
941 return this->begin(); \
943 else if(p == cend()){ \
944 this->emplace_back(BOOST_PP_ENUM(n, BOOST_CONTAINERS_PP_PARAM_FORWARD, _)); \
945 return (this->end()-1); \
947 else{ \
948 size_type pos_num = p - this->cbegin(); \
949 containers_detail::BOOST_PP_CAT(BOOST_PP_CAT(advanced_insert_aux_emplace, n), arg) \
950 <value_type, iterator, BOOST_PP_ENUM_PARAMS(n, P)> \
951 proxy(BOOST_PP_ENUM(n, BOOST_CONTAINERS_PP_PARAM_FORWARD, _)); \
952 this->priv_insert_aux_impl(p, 1, proxy); \
953 return iterator(this->begin() + pos_num); \
957 #define BOOST_PP_LOCAL_LIMITS (1, BOOST_CONTAINERS_MAX_CONSTRUCTOR_PARAMETERS)
958 #include BOOST_PP_LOCAL_ITERATE()
960 #endif //#ifdef BOOST_CONTAINERS_PERFECT_FORWARDING
962 void resize(size_type new_size, const value_type& x)
964 const size_type len = size();
965 if (new_size < len)
966 this->erase(this->members_.m_start + new_size, this->members_.m_finish);
967 else
968 this->insert(this->members_.m_finish, new_size - len, x);
971 void resize(size_type new_size)
973 const size_type len = size();
974 if (new_size < len)
975 this->erase(this->members_.m_start + new_size, this->members_.m_finish);
976 else{
977 size_type n = new_size - this->size();
978 containers_detail::default_construct_aux_proxy<T, iterator, size_type> proxy(n);
979 priv_insert_aux_impl(this->cend(), n, proxy);
983 iterator erase(const_iterator pos)
985 const_iterator next = pos;
986 ++next;
987 difference_type index = pos - this->members_.m_start;
988 if (size_type(index) < (this->size() >> 1)) {
989 boost::interprocess::move_backward(begin(), iterator(pos), iterator(next));
990 pop_front();
992 else {
993 boost::interprocess::move(iterator(next), end(), iterator(pos));
994 pop_back();
996 return this->members_.m_start + index;
999 iterator erase(const_iterator first, const_iterator last)
1001 if (first == this->members_.m_start && last == this->members_.m_finish) {
1002 this->clear();
1003 return this->members_.m_finish;
1005 else {
1006 difference_type n = last - first;
1007 difference_type elems_before = first - this->members_.m_start;
1008 if (elems_before < static_cast<difference_type>(this->size() - n) - elems_before) {
1009 boost::interprocess::move_backward(begin(), iterator(first), iterator(last));
1010 iterator new_start = this->members_.m_start + n;
1011 if(!Base::traits_t::trivial_dctr_after_move)
1012 this->priv_destroy_range(this->members_.m_start, new_start);
1013 this->priv_destroy_nodes(new_start.m_node, this->members_.m_start.m_node);
1014 this->members_.m_start = new_start;
1016 else {
1017 boost::interprocess::move(iterator(last), end(), iterator(first));
1018 iterator new_finish = this->members_.m_finish - n;
1019 if(!Base::traits_t::trivial_dctr_after_move)
1020 this->priv_destroy_range(new_finish, this->members_.m_finish);
1021 this->priv_destroy_nodes(new_finish.m_node + 1, this->members_.m_finish.m_node + 1);
1022 this->members_.m_finish = new_finish;
1024 return this->members_.m_start + elems_before;
1028 void clear()
1030 for (index_pointer node = this->members_.m_start.m_node + 1;
1031 node < this->members_.m_finish.m_node;
1032 ++node) {
1033 this->priv_destroy_range(*node, *node + this->s_buffer_size());
1034 this->priv_deallocate_node(*node);
1037 if (this->members_.m_start.m_node != this->members_.m_finish.m_node) {
1038 this->priv_destroy_range(this->members_.m_start.m_cur, this->members_.m_start.m_last);
1039 this->priv_destroy_range(this->members_.m_finish.m_first, this->members_.m_finish.m_cur);
1040 this->priv_deallocate_node(this->members_.m_finish.m_first);
1042 else
1043 this->priv_destroy_range(this->members_.m_start.m_cur, this->members_.m_finish.m_cur);
1045 this->members_.m_finish = this->members_.m_start;
1048 /// @cond
1049 private:
1051 bool priv_push_back_simple_available() const
1053 return this->members_.m_map &&
1054 (this->members_.m_finish.m_cur != (this->members_.m_finish.m_last - 1));
1057 void *priv_push_back_simple_pos() const
1059 return static_cast<void*>(containers_detail::get_pointer(this->members_.m_finish.m_cur));
1062 void priv_push_back_simple_commit()
1064 ++this->members_.m_finish.m_cur;
1067 bool priv_push_front_simple_available() const
1069 return this->members_.m_map &&
1070 (this->members_.m_start.m_cur != this->members_.m_start.m_first);
1073 void *priv_push_front_simple_pos() const
1074 { return static_cast<void*>(containers_detail::get_pointer(this->members_.m_start.m_cur) - 1); }
1076 void priv_push_front_simple_commit()
1077 { --this->members_.m_start.m_cur; }
1079 template <class InpIt>
1080 void priv_insert_aux(const_iterator pos, InpIt first, InpIt last, std::input_iterator_tag)
1082 for(;first != last; ++first){
1083 this->insert(pos, boost::interprocess::move(value_type(*first)));
1087 template <class FwdIt>
1088 void priv_insert_aux(const_iterator pos, FwdIt first, FwdIt last, std::forward_iterator_tag)
1089 { this->priv_insert_aux(pos, first, last); }
1091 // assign(), a generalized assignment member function. Two
1092 // versions: one that takes a count, and one that takes a range.
1093 // The range version is a member template, so we dispatch on whether
1094 // or not the type is an integer.
1095 void priv_fill_assign(size_type n, const T& val)
1097 if (n > size()) {
1098 std::fill(begin(), end(), val);
1099 this->insert(cend(), n - size(), val);
1101 else {
1102 this->erase(cbegin() + n, cend());
1103 std::fill(begin(), end(), val);
1107 template <class Integer>
1108 void priv_initialize_dispatch(Integer n, Integer x, containers_detail::true_)
1110 this->priv_initialize_map(n);
1111 this->priv_fill_initialize(x);
1114 template <class InpIt>
1115 void priv_initialize_dispatch(InpIt first, InpIt last, containers_detail::false_)
1117 typedef typename std::iterator_traits<InpIt>::iterator_category ItCat;
1118 this->priv_range_initialize(first, last, ItCat());
1121 void priv_destroy_range(iterator p, iterator p2)
1123 for(;p != p2; ++p)
1124 containers_detail::get_pointer(&*p)->~value_type();
1127 void priv_destroy_range(pointer p, pointer p2)
1129 for(;p != p2; ++p)
1130 containers_detail::get_pointer(&*p)->~value_type();
1133 template <class Integer>
1134 void priv_assign_dispatch(Integer n, Integer val, containers_detail::true_)
1135 { this->priv_fill_assign((size_type) n, (T) val); }
1137 template <class InpIt>
1138 void priv_assign_dispatch(InpIt first, InpIt last, containers_detail::false_)
1140 typedef typename std::iterator_traits<InpIt>::iterator_category ItCat;
1141 this->priv_assign_aux(first, last, ItCat());
1144 template <class InpIt>
1145 void priv_assign_aux(InpIt first, InpIt last, std::input_iterator_tag)
1147 iterator cur = begin();
1148 for ( ; first != last && cur != end(); ++cur, ++first)
1149 *cur = *first;
1150 if (first == last)
1151 this->erase(cur, cend());
1152 else
1153 this->insert(cend(), first, last);
1156 template <class FwdIt>
1157 void priv_assign_aux(FwdIt first, FwdIt last, std::forward_iterator_tag)
1159 size_type len = std::distance(first, last);
1160 if (len > size()) {
1161 FwdIt mid = first;
1162 std::advance(mid, size());
1163 std::copy(first, mid, begin());
1164 this->insert(cend(), mid, last);
1166 else
1167 this->erase(std::copy(first, last, begin()), cend());
1170 template <class Integer>
1171 void priv_insert_dispatch(const_iterator pos, Integer n, Integer x, containers_detail::true_)
1172 { this->priv_fill_insert(pos, (size_type) n, (value_type) x); }
1174 template <class InpIt>
1175 void priv_insert_dispatch(const_iterator pos,InpIt first, InpIt last, containers_detail::false_)
1177 typedef typename std::iterator_traits<InpIt>::iterator_category ItCat;
1178 this->priv_insert_aux(pos, first, last, ItCat());
1181 void priv_insert_aux(const_iterator pos, size_type n, const value_type& x)
1183 typedef constant_iterator<value_type, difference_type> c_it;
1184 this->priv_insert_aux(pos, c_it(x, n), c_it());
1187 //Just forward all operations to priv_insert_aux_impl
1188 template <class FwdIt>
1189 void priv_insert_aux(const_iterator p, FwdIt first, FwdIt last)
1191 containers_detail::advanced_insert_aux_proxy<T, FwdIt, iterator> proxy(first, last);
1192 priv_insert_aux_impl(p, (size_type)std::distance(first, last), proxy);
1195 void priv_insert_aux_impl(const_iterator p, size_type n, advanced_insert_aux_int_t &interf)
1197 iterator pos(p);
1198 if(!this->members_.m_map){
1199 this->priv_initialize_map(0);
1200 pos = this->begin();
1203 const difference_type elemsbefore = pos - this->members_.m_start;
1204 size_type length = this->size();
1205 if (elemsbefore < static_cast<difference_type>(length / 2)) {
1206 iterator new_start = this->priv_reserve_elements_at_front(n);
1207 iterator old_start = this->members_.m_start;
1208 pos = this->members_.m_start + elemsbefore;
1209 if (elemsbefore >= difference_type(n)) {
1210 iterator start_n = this->members_.m_start + difference_type(n);
1211 boost::interprocess::uninitialized_move(this->members_.m_start, start_n, new_start);
1212 this->members_.m_start = new_start;
1213 boost::interprocess::move(start_n, pos, old_start);
1214 interf.copy_all_to(pos - difference_type(n));
1216 else {
1217 difference_type mid_count = (difference_type(n) - elemsbefore);
1218 iterator mid_start = old_start - mid_count;
1219 interf.uninitialized_copy_some_and_update(mid_start, mid_count, true);
1220 this->members_.m_start = mid_start;
1221 boost::interprocess::uninitialized_move(old_start, pos, new_start);
1222 this->members_.m_start = new_start;
1223 interf.copy_all_to(old_start);
1226 else {
1227 iterator new_finish = this->priv_reserve_elements_at_back(n);
1228 iterator old_finish = this->members_.m_finish;
1229 const difference_type elemsafter =
1230 difference_type(length) - elemsbefore;
1231 pos = this->members_.m_finish - elemsafter;
1232 if (elemsafter >= difference_type(n)) {
1233 iterator finish_n = this->members_.m_finish - difference_type(n);
1234 boost::interprocess::uninitialized_move(finish_n, this->members_.m_finish, this->members_.m_finish);
1235 this->members_.m_finish = new_finish;
1236 boost::interprocess::move_backward(pos, finish_n, old_finish);
1237 interf.copy_all_to(pos);
1239 else {
1240 interf.uninitialized_copy_some_and_update(old_finish, elemsafter, false);
1241 this->members_.m_finish += n-elemsafter;
1242 boost::interprocess::uninitialized_move(pos, old_finish, this->members_.m_finish);
1243 this->members_.m_finish = new_finish;
1244 interf.copy_all_to(pos);
1249 void priv_fill_insert(const_iterator pos, size_type n, const value_type& x)
1251 typedef constant_iterator<value_type, difference_type> c_it;
1252 this->insert(pos, c_it(x, n), c_it());
1255 // Precondition: this->members_.m_start and this->members_.m_finish have already been initialized,
1256 // but none of the deque's elements have yet been constructed.
1257 void priv_fill_initialize(const value_type& value)
1259 index_pointer cur;
1260 BOOST_TRY {
1261 for (cur = this->members_.m_start.m_node; cur < this->members_.m_finish.m_node; ++cur){
1262 std::uninitialized_fill(*cur, *cur + this->s_buffer_size(), value);
1264 std::uninitialized_fill(this->members_.m_finish.m_first, this->members_.m_finish.m_cur, value);
1266 BOOST_CATCH(...){
1267 this->priv_destroy_range(this->members_.m_start, iterator(*cur, cur));
1268 BOOST_RETHROW
1270 BOOST_CATCH_END
1273 template <class InpIt>
1274 void priv_range_initialize(InpIt first, InpIt last, std::input_iterator_tag)
1276 this->priv_initialize_map(0);
1277 BOOST_TRY {
1278 for ( ; first != last; ++first)
1279 this->push_back(*first);
1281 BOOST_CATCH(...){
1282 this->clear();
1283 BOOST_RETHROW
1285 BOOST_CATCH_END
1288 template <class FwdIt>
1289 void priv_range_initialize(FwdIt first, FwdIt last, std::forward_iterator_tag)
1291 size_type n = 0;
1292 n = std::distance(first, last);
1293 this->priv_initialize_map(n);
1295 index_pointer cur_node;
1296 BOOST_TRY {
1297 for (cur_node = this->members_.m_start.m_node;
1298 cur_node < this->members_.m_finish.m_node;
1299 ++cur_node) {
1300 FwdIt mid = first;
1301 std::advance(mid, this->s_buffer_size());
1302 boost::interprocess::uninitialized_copy_or_move(first, mid, *cur_node);
1303 first = mid;
1305 boost::interprocess::uninitialized_copy_or_move(first, last, this->members_.m_finish.m_first);
1307 BOOST_CATCH(...){
1308 this->priv_destroy_range(this->members_.m_start, iterator(*cur_node, cur_node));
1309 BOOST_RETHROW
1311 BOOST_CATCH_END
1314 // Called only if this->members_.m_finish.m_cur == this->members_.m_finish.m_first.
1315 void priv_pop_back_aux()
1317 this->priv_deallocate_node(this->members_.m_finish.m_first);
1318 this->members_.m_finish.priv_set_node(this->members_.m_finish.m_node - 1);
1319 this->members_.m_finish.m_cur = this->members_.m_finish.m_last - 1;
1320 containers_detail::get_pointer(this->members_.m_finish.m_cur)->~value_type();
1323 // Called only if this->members_.m_start.m_cur == this->members_.m_start.m_last - 1. Note that
1324 // if the deque has at least one element (a precondition for this member
1325 // function), and if this->members_.m_start.m_cur == this->members_.m_start.m_last, then the deque
1326 // must have at least two nodes.
1327 void priv_pop_front_aux()
1329 containers_detail::get_pointer(this->members_.m_start.m_cur)->~value_type();
1330 this->priv_deallocate_node(this->members_.m_start.m_first);
1331 this->members_.m_start.priv_set_node(this->members_.m_start.m_node + 1);
1332 this->members_.m_start.m_cur = this->members_.m_start.m_first;
1335 iterator priv_reserve_elements_at_front(size_type n)
1337 size_type vacancies = this->members_.m_start.m_cur - this->members_.m_start.m_first;
1338 if (n > vacancies){
1339 size_type new_elems = n-vacancies;
1340 size_type new_nodes = (new_elems + this->s_buffer_size() - 1) /
1341 this->s_buffer_size();
1342 size_type s = (size_type)(this->members_.m_start.m_node - this->members_.m_map);
1343 if (new_nodes > s){
1344 this->priv_reallocate_map(new_nodes, true);
1346 size_type i = 1;
1347 BOOST_TRY {
1348 for (; i <= new_nodes; ++i)
1349 *(this->members_.m_start.m_node - i) = this->priv_allocate_node();
1351 BOOST_CATCH(...) {
1352 for (size_type j = 1; j < i; ++j)
1353 this->priv_deallocate_node(*(this->members_.m_start.m_node - j));
1354 BOOST_RETHROW
1356 BOOST_CATCH_END
1358 return this->members_.m_start - difference_type(n);
1361 iterator priv_reserve_elements_at_back(size_type n)
1363 size_type vacancies = (this->members_.m_finish.m_last - this->members_.m_finish.m_cur) - 1;
1364 if (n > vacancies){
1365 size_type new_elems = n - vacancies;
1366 size_type new_nodes = (new_elems + this->s_buffer_size() - 1)/s_buffer_size();
1367 size_type s = (size_type)(this->members_.m_map_size - (this->members_.m_finish.m_node - this->members_.m_map));
1368 if (new_nodes + 1 > s){
1369 this->priv_reallocate_map(new_nodes, false);
1371 size_type i;
1372 BOOST_TRY {
1373 for (i = 1; i <= new_nodes; ++i)
1374 *(this->members_.m_finish.m_node + i) = this->priv_allocate_node();
1376 BOOST_CATCH(...) {
1377 for (size_type j = 1; j < i; ++j)
1378 this->priv_deallocate_node(*(this->members_.m_finish.m_node + j));
1379 BOOST_RETHROW
1381 BOOST_CATCH_END
1383 return this->members_.m_finish + difference_type(n);
1386 void priv_reallocate_map(size_type nodes_to_add, bool add_at_front)
1388 size_type old_num_nodes = this->members_.m_finish.m_node - this->members_.m_start.m_node + 1;
1389 size_type new_num_nodes = old_num_nodes + nodes_to_add;
1391 index_pointer new_nstart;
1392 if (this->members_.m_map_size > 2 * new_num_nodes) {
1393 new_nstart = this->members_.m_map + (this->members_.m_map_size - new_num_nodes) / 2
1394 + (add_at_front ? nodes_to_add : 0);
1395 if (new_nstart < this->members_.m_start.m_node)
1396 boost::interprocess::move(this->members_.m_start.m_node, this->members_.m_finish.m_node + 1, new_nstart);
1397 else
1398 boost::interprocess::move_backward
1399 (this->members_.m_start.m_node, this->members_.m_finish.m_node + 1, new_nstart + old_num_nodes);
1401 else {
1402 size_type new_map_size =
1403 this->members_.m_map_size + containers_detail::max_value(this->members_.m_map_size, nodes_to_add) + 2;
1405 index_pointer new_map = this->priv_allocate_map(new_map_size);
1406 new_nstart = new_map + (new_map_size - new_num_nodes) / 2
1407 + (add_at_front ? nodes_to_add : 0);
1408 boost::interprocess::move(this->members_.m_start.m_node, this->members_.m_finish.m_node + 1, new_nstart);
1409 this->priv_deallocate_map(this->members_.m_map, this->members_.m_map_size);
1411 this->members_.m_map = new_map;
1412 this->members_.m_map_size = new_map_size;
1415 this->members_.m_start.priv_set_node(new_nstart);
1416 this->members_.m_finish.priv_set_node(new_nstart + old_num_nodes - 1);
1418 /// @endcond
1421 // Nonmember functions.
1422 template <class T, class Alloc>
1423 inline bool operator==(const deque<T, Alloc>& x,
1424 const deque<T, Alloc>& y)
1426 return x.size() == y.size() && equal(x.begin(), x.end(), y.begin());
1429 template <class T, class Alloc>
1430 inline bool operator<(const deque<T, Alloc>& x,
1431 const deque<T, Alloc>& y)
1433 return lexicographical_compare(x.begin(), x.end(), y.begin(), y.end());
1436 template <class T, class Alloc>
1437 inline bool operator!=(const deque<T, Alloc>& x,
1438 const deque<T, Alloc>& y)
1439 { return !(x == y); }
1441 template <class T, class Alloc>
1442 inline bool operator>(const deque<T, Alloc>& x,
1443 const deque<T, Alloc>& y)
1444 { return y < x; }
1446 template <class T, class Alloc>
1447 inline bool operator<=(const deque<T, Alloc>& x,
1448 const deque<T, Alloc>& y)
1449 { return !(y < x); }
1451 template <class T, class Alloc>
1452 inline bool operator>=(const deque<T, Alloc>& x,
1453 const deque<T, Alloc>& y)
1454 { return !(x < y); }
1457 template <class T, class A>
1458 inline void swap(deque<T, A>& x, deque<T, A>& y)
1459 { x.swap(y); }
1463 /// @cond
1465 namespace boost {
1466 namespace interprocess {
1468 //!has_trivial_destructor_after_move<> == true_type
1469 //!specialization for optimizations
1470 template <class T, class A>
1471 struct has_trivial_destructor_after_move<boost::interprocess_container::deque<T, A> >
1473 enum { value = has_trivial_destructor<A>::value };
1478 /// @endcond
1480 #include <boost/interprocess/containers/container/detail/config_end.hpp>
1482 #endif // #ifndef BOOST_CONTAINERS_DEQUE_HPP