annotate DEPENDENCIES/generic/include/boost/container/deque.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents c530137014c0
children
rev   line source
Chris@16 1 //////////////////////////////////////////////////////////////////////////////
Chris@16 2 //
Chris@101 3 // (C) Copyright Ion Gaztanaga 2005-2013. Distributed under the Boost
Chris@16 4 // Software License, Version 1.0. (See accompanying file
Chris@16 5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Chris@16 6 //
Chris@16 7 // See http://www.boost.org/libs/container for documentation.
Chris@16 8 //
Chris@16 9 //////////////////////////////////////////////////////////////////////////////
Chris@16 10 #ifndef BOOST_CONTAINER_DEQUE_HPP
Chris@16 11 #define BOOST_CONTAINER_DEQUE_HPP
Chris@16 12
Chris@101 13 #ifndef BOOST_CONFIG_HPP
Chris@101 14 # include <boost/config.hpp>
Chris@101 15 #endif
Chris@101 16
Chris@101 17 #if defined(BOOST_HAS_PRAGMA_ONCE)
Chris@16 18 # pragma once
Chris@16 19 #endif
Chris@16 20
Chris@16 21 #include <boost/container/detail/config_begin.hpp>
Chris@16 22 #include <boost/container/detail/workaround.hpp>
Chris@101 23 // container
Chris@16 24 #include <boost/container/allocator_traits.hpp>
Chris@16 25 #include <boost/container/container_fwd.hpp>
Chris@101 26 #include <boost/container/new_allocator.hpp> //new_allocator
Chris@16 27 #include <boost/container/throw_exception.hpp>
Chris@101 28 // container/detail
Chris@101 29 #include <boost/container/detail/advanced_insert_int.hpp>
Chris@101 30 #include <boost/container/detail/algorithm.hpp> //algo_equal(), algo_lexicographical_compare
Chris@101 31 #include <boost/container/detail/alloc_helpers.hpp>
Chris@101 32 #include <boost/container/detail/copy_move_algo.hpp>
Chris@101 33 #include <boost/container/detail/iterator.hpp>
Chris@101 34 #include <boost/container/detail/iterator_to_raw_pointer.hpp>
Chris@101 35 #include <boost/container/detail/iterators.hpp>
Chris@101 36 #include <boost/container/detail/min_max.hpp>
Chris@101 37 #include <boost/container/detail/mpl.hpp>
Chris@101 38 #include <boost/container/detail/to_raw_pointer.hpp>
Chris@101 39 #include <boost/container/detail/type_traits.hpp>
Chris@101 40 // move
Chris@101 41 #include <boost/move/adl_move_swap.hpp>
Chris@101 42 #include <boost/move/iterator.hpp>
Chris@101 43 #include <boost/move/traits.hpp>
Chris@101 44 #include <boost/move/utility_core.hpp>
Chris@101 45 // move/detail
Chris@101 46 #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
Chris@101 47 #include <boost/move/detail/fwd_macros.hpp>
Chris@101 48 #endif
Chris@101 49 #include <boost/move/detail/move_helpers.hpp>
Chris@101 50 // other
Chris@101 51 #include <boost/assert.hpp>
Chris@101 52 #include <boost/core/no_exceptions_support.hpp>
Chris@101 53 // std
Chris@16 54 #include <cstddef>
Chris@101 55
Chris@101 56 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
Chris@101 57 #include <initializer_list>
Chris@101 58 #endif
Chris@16 59
Chris@16 60 namespace boost {
Chris@16 61 namespace container {
Chris@16 62
Chris@101 63 #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
Chris@16 64 template <class T, class Allocator>
Chris@16 65 class deque;
Chris@16 66
Chris@16 67 template <class T>
Chris@16 68 struct deque_value_traits
Chris@16 69 {
Chris@16 70 typedef T value_type;
Chris@101 71 static const bool trivial_dctr = container_detail::is_trivially_destructible<value_type>::value;
Chris@16 72 static const bool trivial_dctr_after_move = ::boost::has_trivial_destructor_after_move<value_type>::value;
Chris@16 73 };
Chris@16 74
Chris@16 75 // Note: this function is simply a kludge to work around several compilers'
Chris@16 76 // bugs in handling constant expressions.
Chris@16 77 template<class T>
Chris@16 78 struct deque_buf_size
Chris@16 79 {
Chris@16 80 static const std::size_t min_size = 512u;
Chris@16 81 static const std::size_t sizeof_t = sizeof(T);
Chris@16 82 static const std::size_t value = sizeof_t < min_size ? (min_size/sizeof_t) : std::size_t(1);
Chris@16 83 };
Chris@16 84
Chris@16 85 namespace container_detail {
Chris@16 86
Chris@16 87 // Class invariants:
Chris@16 88 // For any nonsingular iterator i:
Chris@16 89 // i.node is the address of an element in the map array. The
Chris@16 90 // contents of i.node is a pointer to the beginning of a node.
Chris@16 91 // i.first == //(i.node)
Chris@16 92 // i.last == i.first + node_size
Chris@16 93 // i.cur is a pointer in the range [i.first, i.last). NOTE:
Chris@16 94 // the implication of this is that i.cur is always a dereferenceable
Chris@16 95 // pointer, even if i is a past-the-end iterator.
Chris@16 96 // Start and Finish are always nonsingular iterators. NOTE: this means
Chris@16 97 // that an empty deque must have one node, and that a deque
Chris@16 98 // with N elements, where N is the buffer size, must have two nodes.
Chris@16 99 // For every node other than start.node and finish.node, every element
Chris@16 100 // in the node is an initialized object. If start.node == finish.node,
Chris@16 101 // then [start.cur, finish.cur) are initialized objects, and
Chris@16 102 // the elements outside that range are uninitialized storage. Otherwise,
Chris@16 103 // [start.cur, start.last) and [finish.first, finish.cur) are initialized
Chris@16 104 // objects, and [start.first, start.cur) and [finish.cur, finish.last)
Chris@16 105 // are uninitialized storage.
Chris@101 106 // [map, map + map_size) is a valid, non-empty range.
Chris@16 107 // [start.node, finish.node] is a valid range contained within
Chris@101 108 // [map, map + map_size).
Chris@101 109 // A pointer in the range [map, map + map_size) points to an allocated node
Chris@16 110 // if and only if the pointer is in the range [start.node, finish.node].
Chris@16 111 template<class Pointer, bool IsConst>
Chris@16 112 class deque_iterator
Chris@16 113 {
Chris@16 114 public:
Chris@101 115 typedef std::random_access_iterator_tag iterator_category;
Chris@16 116 typedef typename boost::intrusive::pointer_traits<Pointer>::element_type value_type;
Chris@16 117 typedef typename boost::intrusive::pointer_traits<Pointer>::difference_type difference_type;
Chris@16 118 typedef typename if_c
Chris@16 119 < IsConst
Chris@16 120 , typename boost::intrusive::pointer_traits<Pointer>::template
Chris@16 121 rebind_pointer<const value_type>::type
Chris@16 122 , Pointer
Chris@16 123 >::type pointer;
Chris@16 124 typedef typename if_c
Chris@16 125 < IsConst
Chris@16 126 , const value_type&
Chris@16 127 , value_type&
Chris@16 128 >::type reference;
Chris@16 129
Chris@16 130 static std::size_t s_buffer_size()
Chris@16 131 { return deque_buf_size<value_type>::value; }
Chris@16 132
Chris@16 133 typedef Pointer val_alloc_ptr;
Chris@16 134 typedef typename boost::intrusive::pointer_traits<Pointer>::
Chris@101 135 template rebind_pointer<Pointer>::type index_pointer;
Chris@16 136
Chris@16 137 Pointer m_cur;
Chris@16 138 Pointer m_first;
Chris@16 139 Pointer m_last;
Chris@16 140 index_pointer m_node;
Chris@16 141
Chris@16 142 public:
Chris@16 143
Chris@16 144 Pointer get_cur() const { return m_cur; }
Chris@16 145 Pointer get_first() const { return m_first; }
Chris@16 146 Pointer get_last() const { return m_last; }
Chris@16 147 index_pointer get_node() const { return m_node; }
Chris@16 148
Chris@101 149 deque_iterator(val_alloc_ptr x, index_pointer y) BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 150 : m_cur(x), m_first(*y), m_last(*y + s_buffer_size()), m_node(y)
Chris@16 151 {}
Chris@16 152
Chris@101 153 deque_iterator() BOOST_NOEXCEPT_OR_NOTHROW
Chris@101 154 : m_cur(), m_first(), m_last(), m_node() //Value initialization to achieve "null iterators" (N3644)
Chris@16 155 {}
Chris@16 156
Chris@101 157 deque_iterator(deque_iterator<Pointer, false> const& x) BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 158 : m_cur(x.get_cur()), m_first(x.get_first()), m_last(x.get_last()), m_node(x.get_node())
Chris@16 159 {}
Chris@16 160
Chris@101 161 deque_iterator(Pointer cur, Pointer first, Pointer last, index_pointer node) BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 162 : m_cur(cur), m_first(first), m_last(last), m_node(node)
Chris@16 163 {}
Chris@16 164
Chris@101 165 deque_iterator<Pointer, false> unconst() const BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 166 {
Chris@16 167 return deque_iterator<Pointer, false>(this->get_cur(), this->get_first(), this->get_last(), this->get_node());
Chris@16 168 }
Chris@16 169
Chris@101 170 reference operator*() const BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 171 { return *this->m_cur; }
Chris@16 172
Chris@101 173 pointer operator->() const BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 174 { return this->m_cur; }
Chris@16 175
Chris@101 176 difference_type operator-(const deque_iterator& x) const BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 177 {
Chris@16 178 if(!this->m_cur && !x.m_cur){
Chris@16 179 return 0;
Chris@16 180 }
Chris@16 181 return difference_type(this->s_buffer_size()) * (this->m_node - x.m_node - 1) +
Chris@16 182 (this->m_cur - this->m_first) + (x.m_last - x.m_cur);
Chris@16 183 }
Chris@16 184
Chris@101 185 deque_iterator& operator++() BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 186 {
Chris@16 187 ++this->m_cur;
Chris@16 188 if (this->m_cur == this->m_last) {
Chris@16 189 this->priv_set_node(this->m_node + 1);
Chris@16 190 this->m_cur = this->m_first;
Chris@16 191 }
Chris@16 192 return *this;
Chris@16 193 }
Chris@16 194
Chris@101 195 deque_iterator operator++(int) BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 196 {
Chris@16 197 deque_iterator tmp(*this);
Chris@16 198 ++*this;
Chris@16 199 return tmp;
Chris@16 200 }
Chris@16 201
Chris@101 202 deque_iterator& operator--() BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 203 {
Chris@16 204 if (this->m_cur == this->m_first) {
Chris@16 205 this->priv_set_node(this->m_node - 1);
Chris@16 206 this->m_cur = this->m_last;
Chris@16 207 }
Chris@16 208 --this->m_cur;
Chris@16 209 return *this;
Chris@16 210 }
Chris@16 211
Chris@101 212 deque_iterator operator--(int) BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 213 {
Chris@16 214 deque_iterator tmp(*this);
Chris@16 215 --*this;
Chris@16 216 return tmp;
Chris@16 217 }
Chris@16 218
Chris@101 219 deque_iterator& operator+=(difference_type n) BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 220 {
Chris@16 221 difference_type offset = n + (this->m_cur - this->m_first);
Chris@16 222 if (offset >= 0 && offset < difference_type(this->s_buffer_size()))
Chris@16 223 this->m_cur += n;
Chris@16 224 else {
Chris@16 225 difference_type node_offset =
Chris@16 226 offset > 0 ? offset / difference_type(this->s_buffer_size())
Chris@16 227 : -difference_type((-offset - 1) / this->s_buffer_size()) - 1;
Chris@16 228 this->priv_set_node(this->m_node + node_offset);
Chris@16 229 this->m_cur = this->m_first +
Chris@16 230 (offset - node_offset * difference_type(this->s_buffer_size()));
Chris@16 231 }
Chris@16 232 return *this;
Chris@16 233 }
Chris@16 234
Chris@101 235 deque_iterator operator+(difference_type n) const BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 236 { deque_iterator tmp(*this); return tmp += n; }
Chris@16 237
Chris@101 238 deque_iterator& operator-=(difference_type n) BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 239 { return *this += -n; }
Chris@101 240
Chris@101 241 deque_iterator operator-(difference_type n) const BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 242 { deque_iterator tmp(*this); return tmp -= n; }
Chris@16 243
Chris@101 244 reference operator[](difference_type n) const BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 245 { return *(*this + n); }
Chris@16 246
Chris@101 247 friend bool operator==(const deque_iterator& l, const deque_iterator& r) BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 248 { return l.m_cur == r.m_cur; }
Chris@16 249
Chris@101 250 friend bool operator!=(const deque_iterator& l, const deque_iterator& r) BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 251 { return l.m_cur != r.m_cur; }
Chris@16 252
Chris@101 253 friend bool operator<(const deque_iterator& l, const deque_iterator& r) BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 254 { return (l.m_node == r.m_node) ? (l.m_cur < r.m_cur) : (l.m_node < r.m_node); }
Chris@16 255
Chris@101 256 friend bool operator>(const deque_iterator& l, const deque_iterator& r) BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 257 { return r < l; }
Chris@16 258
Chris@101 259 friend bool operator<=(const deque_iterator& l, const deque_iterator& r) BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 260 { return !(r < l); }
Chris@16 261
Chris@101 262 friend bool operator>=(const deque_iterator& l, const deque_iterator& r) BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 263 { return !(l < r); }
Chris@16 264
Chris@101 265 void priv_set_node(index_pointer new_node) BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 266 {
Chris@16 267 this->m_node = new_node;
Chris@16 268 this->m_first = *new_node;
Chris@16 269 this->m_last = this->m_first + this->s_buffer_size();
Chris@16 270 }
Chris@16 271
Chris@101 272 friend deque_iterator operator+(difference_type n, deque_iterator x) BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 273 { return x += n; }
Chris@16 274 };
Chris@16 275
Chris@16 276 } //namespace container_detail {
Chris@16 277
Chris@16 278 // Deque base class. It has two purposes. First, its constructor
Chris@16 279 // and destructor allocate (but don't initialize) storage. This makes
Chris@16 280 // exception safety easier.
Chris@16 281 template <class Allocator>
Chris@16 282 class deque_base
Chris@16 283 {
Chris@16 284 BOOST_COPYABLE_AND_MOVABLE(deque_base)
Chris@16 285 public:
Chris@16 286 typedef allocator_traits<Allocator> val_alloc_traits_type;
Chris@16 287 typedef typename val_alloc_traits_type::value_type val_alloc_val;
Chris@16 288 typedef typename val_alloc_traits_type::pointer val_alloc_ptr;
Chris@16 289 typedef typename val_alloc_traits_type::const_pointer val_alloc_cptr;
Chris@16 290 typedef typename val_alloc_traits_type::reference val_alloc_ref;
Chris@16 291 typedef typename val_alloc_traits_type::const_reference val_alloc_cref;
Chris@16 292 typedef typename val_alloc_traits_type::difference_type val_alloc_diff;
Chris@16 293 typedef typename val_alloc_traits_type::size_type val_alloc_size;
Chris@16 294 typedef typename val_alloc_traits_type::template
Chris@16 295 portable_rebind_alloc<val_alloc_ptr>::type ptr_alloc_t;
Chris@16 296 typedef allocator_traits<ptr_alloc_t> ptr_alloc_traits_type;
Chris@16 297 typedef typename ptr_alloc_traits_type::value_type ptr_alloc_val;
Chris@16 298 typedef typename ptr_alloc_traits_type::pointer ptr_alloc_ptr;
Chris@16 299 typedef typename ptr_alloc_traits_type::const_pointer ptr_alloc_cptr;
Chris@16 300 typedef typename ptr_alloc_traits_type::reference ptr_alloc_ref;
Chris@16 301 typedef typename ptr_alloc_traits_type::const_reference ptr_alloc_cref;
Chris@16 302 typedef Allocator allocator_type;
Chris@16 303 typedef allocator_type stored_allocator_type;
Chris@16 304 typedef val_alloc_size size_type;
Chris@16 305
Chris@16 306 protected:
Chris@16 307
Chris@16 308 typedef deque_value_traits<val_alloc_val> traits_t;
Chris@16 309 typedef ptr_alloc_t map_allocator_type;
Chris@16 310
Chris@101 311 static size_type s_buffer_size() BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 312 { return deque_buf_size<val_alloc_val>::value; }
Chris@16 313
Chris@16 314 val_alloc_ptr priv_allocate_node()
Chris@16 315 { return this->alloc().allocate(s_buffer_size()); }
Chris@16 316
Chris@101 317 void priv_deallocate_node(val_alloc_ptr p) BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 318 { this->alloc().deallocate(p, s_buffer_size()); }
Chris@16 319
Chris@16 320 ptr_alloc_ptr priv_allocate_map(size_type n)
Chris@16 321 { return this->ptr_alloc().allocate(n); }
Chris@16 322
Chris@101 323 void priv_deallocate_map(ptr_alloc_ptr p, size_type n) BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 324 { this->ptr_alloc().deallocate(p, n); }
Chris@16 325
Chris@16 326 typedef container_detail::deque_iterator<val_alloc_ptr, false> iterator;
Chris@16 327 typedef container_detail::deque_iterator<val_alloc_ptr, true > const_iterator;
Chris@16 328
Chris@16 329 deque_base(size_type num_elements, const allocator_type& a)
Chris@16 330 : members_(a)
Chris@16 331 { this->priv_initialize_map(num_elements); }
Chris@16 332
Chris@16 333 explicit deque_base(const allocator_type& a)
Chris@16 334 : members_(a)
Chris@16 335 {}
Chris@16 336
Chris@16 337 deque_base()
Chris@16 338 : members_()
Chris@16 339 {}
Chris@16 340
Chris@16 341 explicit deque_base(BOOST_RV_REF(deque_base) x)
Chris@16 342 : members_( boost::move(x.ptr_alloc())
Chris@16 343 , boost::move(x.alloc()) )
Chris@16 344 {}
Chris@16 345
Chris@16 346 ~deque_base()
Chris@16 347 {
Chris@16 348 if (this->members_.m_map) {
Chris@16 349 this->priv_destroy_nodes(this->members_.m_start.m_node, this->members_.m_finish.m_node + 1);
Chris@16 350 this->priv_deallocate_map(this->members_.m_map, this->members_.m_map_size);
Chris@16 351 }
Chris@16 352 }
Chris@16 353
Chris@16 354 private:
Chris@16 355 deque_base(const deque_base&);
Chris@101 356
Chris@16 357 protected:
Chris@16 358
Chris@101 359 void swap_members(deque_base &x) BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 360 {
Chris@101 361 ::boost::adl_move_swap(this->members_.m_start, x.members_.m_start);
Chris@101 362 ::boost::adl_move_swap(this->members_.m_finish, x.members_.m_finish);
Chris@101 363 ::boost::adl_move_swap(this->members_.m_map, x.members_.m_map);
Chris@101 364 ::boost::adl_move_swap(this->members_.m_map_size, x.members_.m_map_size);
Chris@16 365 }
Chris@16 366
Chris@16 367 void priv_initialize_map(size_type num_elements)
Chris@16 368 {
Chris@16 369 // if(num_elements){
Chris@16 370 size_type num_nodes = num_elements / s_buffer_size() + 1;
Chris@16 371
Chris@16 372 this->members_.m_map_size = container_detail::max_value((size_type) InitialMapSize, num_nodes + 2);
Chris@16 373 this->members_.m_map = this->priv_allocate_map(this->members_.m_map_size);
Chris@16 374
Chris@16 375 ptr_alloc_ptr nstart = this->members_.m_map + (this->members_.m_map_size - num_nodes) / 2;
Chris@16 376 ptr_alloc_ptr nfinish = nstart + num_nodes;
Chris@101 377
Chris@16 378 BOOST_TRY {
Chris@16 379 this->priv_create_nodes(nstart, nfinish);
Chris@16 380 }
Chris@16 381 BOOST_CATCH(...){
Chris@16 382 this->priv_deallocate_map(this->members_.m_map, this->members_.m_map_size);
Chris@16 383 this->members_.m_map = 0;
Chris@16 384 this->members_.m_map_size = 0;
Chris@16 385 BOOST_RETHROW
Chris@16 386 }
Chris@16 387 BOOST_CATCH_END
Chris@16 388
Chris@16 389 this->members_.m_start.priv_set_node(nstart);
Chris@16 390 this->members_.m_finish.priv_set_node(nfinish - 1);
Chris@16 391 this->members_.m_start.m_cur = this->members_.m_start.m_first;
Chris@16 392 this->members_.m_finish.m_cur = this->members_.m_finish.m_first +
Chris@16 393 num_elements % s_buffer_size();
Chris@16 394 // }
Chris@16 395 }
Chris@16 396
Chris@16 397 void priv_create_nodes(ptr_alloc_ptr nstart, ptr_alloc_ptr nfinish)
Chris@16 398 {
Chris@101 399 ptr_alloc_ptr cur = nstart;
Chris@16 400 BOOST_TRY {
Chris@101 401 for (; cur < nfinish; ++cur)
Chris@16 402 *cur = this->priv_allocate_node();
Chris@16 403 }
Chris@16 404 BOOST_CATCH(...){
Chris@16 405 this->priv_destroy_nodes(nstart, cur);
Chris@16 406 BOOST_RETHROW
Chris@16 407 }
Chris@16 408 BOOST_CATCH_END
Chris@16 409 }
Chris@16 410
Chris@101 411 void priv_destroy_nodes(ptr_alloc_ptr nstart, ptr_alloc_ptr nfinish) BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 412 {
Chris@16 413 for (ptr_alloc_ptr n = nstart; n < nfinish; ++n)
Chris@16 414 this->priv_deallocate_node(*n);
Chris@16 415 }
Chris@16 416
Chris@101 417 void priv_clear_map() BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 418 {
Chris@16 419 if (this->members_.m_map) {
Chris@16 420 this->priv_destroy_nodes(this->members_.m_start.m_node, this->members_.m_finish.m_node + 1);
Chris@16 421 this->priv_deallocate_map(this->members_.m_map, this->members_.m_map_size);
Chris@16 422 this->members_.m_map = 0;
Chris@16 423 this->members_.m_map_size = 0;
Chris@16 424 this->members_.m_start = iterator();
Chris@16 425 this->members_.m_finish = this->members_.m_start;
Chris@16 426 }
Chris@16 427 }
Chris@16 428
Chris@16 429 enum { InitialMapSize = 8 };
Chris@16 430
Chris@16 431 protected:
Chris@16 432 struct members_holder
Chris@16 433 : public ptr_alloc_t
Chris@16 434 , public allocator_type
Chris@16 435 {
Chris@16 436 members_holder()
Chris@16 437 : map_allocator_type(), allocator_type()
Chris@16 438 , m_map(0), m_map_size(0)
Chris@16 439 , m_start(), m_finish(m_start)
Chris@16 440 {}
Chris@16 441
Chris@16 442 explicit members_holder(const allocator_type &a)
Chris@16 443 : map_allocator_type(a), allocator_type(a)
Chris@16 444 , m_map(0), m_map_size(0)
Chris@16 445 , m_start(), m_finish(m_start)
Chris@16 446 {}
Chris@16 447
Chris@16 448 template<class ValAllocConvertible, class PtrAllocConvertible>
Chris@16 449 members_holder(BOOST_FWD_REF(PtrAllocConvertible) pa, BOOST_FWD_REF(ValAllocConvertible) va)
Chris@16 450 : map_allocator_type(boost::forward<PtrAllocConvertible>(pa))
Chris@16 451 , allocator_type (boost::forward<ValAllocConvertible>(va))
Chris@16 452 , m_map(0), m_map_size(0)
Chris@16 453 , m_start(), m_finish(m_start)
Chris@16 454 {}
Chris@16 455
Chris@16 456 ptr_alloc_ptr m_map;
Chris@16 457 val_alloc_size m_map_size;
Chris@16 458 iterator m_start;
Chris@16 459 iterator m_finish;
Chris@16 460 } members_;
Chris@16 461
Chris@101 462 ptr_alloc_t &ptr_alloc() BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 463 { return members_; }
Chris@16 464
Chris@101 465 const ptr_alloc_t &ptr_alloc() const BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 466 { return members_; }
Chris@101 467
Chris@101 468 allocator_type &alloc() BOOST_NOEXCEPT_OR_NOTHROW
Chris@101 469 { return members_; }
Chris@101 470
Chris@101 471 const allocator_type &alloc() const BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 472 { return members_; }
Chris@16 473 };
Chris@101 474 #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
Chris@16 475
Chris@101 476 #ifdef BOOST_CONTAINER_DOXYGEN_INVOKED
Chris@101 477 //! A double-ended queue is a sequence that supports random access to elements, constant time insertion
Chris@101 478 //! and removal of elements at the end of the sequence, and linear time insertion and removal of elements in the middle.
Chris@16 479 //!
Chris@101 480 //! \tparam T The type of object that is stored in the deque
Chris@101 481 //! \tparam Allocator The allocator used for all internal memory management
Chris@101 482 template <class T, class Allocator = new_allocator<T> >
Chris@16 483 #else
Chris@16 484 template <class T, class Allocator>
Chris@16 485 #endif
Chris@16 486 class deque : protected deque_base<Allocator>
Chris@16 487 {
Chris@101 488 #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
Chris@16 489 private:
Chris@16 490 typedef deque_base<Allocator> Base;
Chris@101 491 #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
Chris@16 492
Chris@16 493 public:
Chris@16 494
Chris@16 495 //////////////////////////////////////////////
Chris@16 496 //
Chris@16 497 // types
Chris@16 498 //
Chris@16 499 //////////////////////////////////////////////
Chris@16 500
Chris@16 501 typedef T value_type;
Chris@16 502 typedef typename ::boost::container::allocator_traits<Allocator>::pointer pointer;
Chris@16 503 typedef typename ::boost::container::allocator_traits<Allocator>::const_pointer const_pointer;
Chris@16 504 typedef typename ::boost::container::allocator_traits<Allocator>::reference reference;
Chris@16 505 typedef typename ::boost::container::allocator_traits<Allocator>::const_reference const_reference;
Chris@16 506 typedef typename ::boost::container::allocator_traits<Allocator>::size_type size_type;
Chris@16 507 typedef typename ::boost::container::allocator_traits<Allocator>::difference_type difference_type;
Chris@16 508 typedef Allocator allocator_type;
Chris@16 509 typedef BOOST_CONTAINER_IMPDEF(allocator_type) stored_allocator_type;
Chris@16 510 typedef BOOST_CONTAINER_IMPDEF(typename Base::iterator) iterator;
Chris@16 511 typedef BOOST_CONTAINER_IMPDEF(typename Base::const_iterator) const_iterator;
Chris@101 512 typedef BOOST_CONTAINER_IMPDEF(boost::container::reverse_iterator<iterator>) reverse_iterator;
Chris@101 513 typedef BOOST_CONTAINER_IMPDEF(boost::container::reverse_iterator<const_iterator>) const_reverse_iterator;
Chris@16 514
Chris@101 515 #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
Chris@16 516
Chris@16 517 private: // Internal typedefs
Chris@16 518 BOOST_COPYABLE_AND_MOVABLE(deque)
Chris@16 519 typedef typename Base::ptr_alloc_ptr index_pointer;
Chris@16 520 static size_type s_buffer_size()
Chris@16 521 { return Base::s_buffer_size(); }
Chris@16 522 typedef allocator_traits<Allocator> allocator_traits_type;
Chris@16 523
Chris@101 524 #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
Chris@16 525
Chris@16 526 public:
Chris@16 527 //////////////////////////////////////////////
Chris@16 528 //
Chris@16 529 // construct/copy/destroy
Chris@16 530 //
Chris@16 531 //////////////////////////////////////////////
Chris@16 532
Chris@16 533 //! <b>Effects</b>: Default constructors a deque.
Chris@16 534 //!
Chris@16 535 //! <b>Throws</b>: If allocator_type's default constructor throws.
Chris@16 536 //!
Chris@16 537 //! <b>Complexity</b>: Constant.
Chris@16 538 deque()
Chris@16 539 : Base()
Chris@16 540 {}
Chris@16 541
Chris@16 542 //! <b>Effects</b>: Constructs a deque taking the allocator as parameter.
Chris@16 543 //!
Chris@16 544 //! <b>Throws</b>: Nothing
Chris@16 545 //!
Chris@16 546 //! <b>Complexity</b>: Constant.
Chris@101 547 explicit deque(const allocator_type& a) BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 548 : Base(a)
Chris@16 549 {}
Chris@16 550
Chris@101 551 //! <b>Effects</b>: Constructs a deque
Chris@16 552 //! and inserts n value initialized values.
Chris@16 553 //!
Chris@101 554 //! <b>Throws</b>: If allocator_type's default constructor
Chris@101 555 //! throws or T's value initialization throws.
Chris@16 556 //!
Chris@16 557 //! <b>Complexity</b>: Linear to n.
Chris@16 558 explicit deque(size_type n)
Chris@16 559 : Base(n, allocator_type())
Chris@16 560 {
Chris@101 561 container_detail::insert_value_initialized_n_proxy<Allocator, iterator> proxy;
Chris@101 562 proxy.uninitialized_copy_n_and_update(this->alloc(), this->begin(), n);
Chris@16 563 //deque_base will deallocate in case of exception...
Chris@16 564 }
Chris@16 565
Chris@101 566 //! <b>Effects</b>: Constructs a deque
Chris@16 567 //! and inserts n default initialized values.
Chris@16 568 //!
Chris@101 569 //! <b>Throws</b>: If allocator_type's default constructor
Chris@101 570 //! throws or T's default initialization or copy constructor throws.
Chris@16 571 //!
Chris@16 572 //! <b>Complexity</b>: Linear to n.
Chris@16 573 //!
Chris@16 574 //! <b>Note</b>: Non-standard extension
Chris@16 575 deque(size_type n, default_init_t)
Chris@16 576 : Base(n, allocator_type())
Chris@16 577 {
Chris@101 578 container_detail::insert_default_initialized_n_proxy<Allocator, iterator> proxy;
Chris@101 579 proxy.uninitialized_copy_n_and_update(this->alloc(), this->begin(), n);
Chris@101 580 //deque_base will deallocate in case of exception...
Chris@101 581 }
Chris@101 582
Chris@101 583 //! <b>Effects</b>: Constructs a deque that will use a copy of allocator a
Chris@101 584 //! and inserts n value initialized values.
Chris@101 585 //!
Chris@101 586 //! <b>Throws</b>: If allocator_type's default constructor
Chris@101 587 //! throws or T's value initialization throws.
Chris@101 588 //!
Chris@101 589 //! <b>Complexity</b>: Linear to n.
Chris@101 590 explicit deque(size_type n, const allocator_type &a)
Chris@101 591 : Base(n, a)
Chris@101 592 {
Chris@101 593 container_detail::insert_value_initialized_n_proxy<Allocator, iterator> proxy;
Chris@101 594 proxy.uninitialized_copy_n_and_update(this->alloc(), this->begin(), n);
Chris@101 595 //deque_base will deallocate in case of exception...
Chris@101 596 }
Chris@101 597
Chris@101 598 //! <b>Effects</b>: Constructs a deque that will use a copy of allocator a
Chris@101 599 //! and inserts n default initialized values.
Chris@101 600 //!
Chris@101 601 //! <b>Throws</b>: If allocator_type's default constructor
Chris@101 602 //! throws or T's default initialization or copy constructor throws.
Chris@101 603 //!
Chris@101 604 //! <b>Complexity</b>: Linear to n.
Chris@101 605 //!
Chris@101 606 //! <b>Note</b>: Non-standard extension
Chris@101 607 deque(size_type n, default_init_t, const allocator_type &a)
Chris@101 608 : Base(n, a)
Chris@101 609 {
Chris@101 610 container_detail::insert_default_initialized_n_proxy<Allocator, iterator> proxy;
Chris@101 611 proxy.uninitialized_copy_n_and_update(this->alloc(), this->begin(), n);
Chris@16 612 //deque_base will deallocate in case of exception...
Chris@16 613 }
Chris@16 614
Chris@16 615 //! <b>Effects</b>: Constructs a deque that will use a copy of allocator a
Chris@16 616 //! and inserts n copies of value.
Chris@16 617 //!
Chris@101 618 //! <b>Throws</b>: If allocator_type's default constructor
Chris@101 619 //! throws or T's copy constructor throws.
Chris@16 620 //!
Chris@16 621 //! <b>Complexity</b>: Linear to n.
Chris@16 622 deque(size_type n, const value_type& value,
Chris@16 623 const allocator_type& a = allocator_type())
Chris@16 624 : Base(n, a)
Chris@16 625 { this->priv_fill_initialize(value); }
Chris@16 626
Chris@16 627 //! <b>Effects</b>: Constructs a deque that will use a copy of allocator a
Chris@16 628 //! and inserts a copy of the range [first, last) in the deque.
Chris@16 629 //!
Chris@101 630 //! <b>Throws</b>: If allocator_type's default constructor
Chris@101 631 //! throws or T's constructor taking a dereferenced InIt throws.
Chris@16 632 //!
Chris@16 633 //! <b>Complexity</b>: Linear to the range [first, last).
Chris@16 634 template <class InIt>
Chris@16 635 deque(InIt first, InIt last, const allocator_type& a = allocator_type()
Chris@16 636 #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
Chris@16 637 , typename container_detail::enable_if_c
Chris@16 638 < !container_detail::is_convertible<InIt, size_type>::value
Chris@16 639 >::type * = 0
Chris@16 640 #endif
Chris@16 641 )
Chris@16 642 : Base(a)
Chris@16 643 {
Chris@101 644 this->priv_range_initialize(first, last);
Chris@16 645 }
Chris@16 646
Chris@101 647 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
Chris@101 648 //! <b>Effects</b>: Constructs a deque that will use a copy of allocator a
Chris@101 649 //! and inserts a copy of the range [il.begin(), il.end()) in the deque.
Chris@101 650 //!
Chris@101 651 //! <b>Throws</b>: If allocator_type's default constructor
Chris@101 652 //! throws or T's constructor taking a dereferenced std::initializer_list iterator throws.
Chris@101 653 //!
Chris@101 654 //! <b>Complexity</b>: Linear to the range [il.begin(), il.end()).
Chris@101 655 deque(std::initializer_list<value_type> il, const allocator_type& a = allocator_type())
Chris@101 656 : Base(a)
Chris@101 657 {
Chris@101 658 this->priv_range_initialize(il.begin(), il.end());
Chris@101 659 }
Chris@101 660 #endif
Chris@101 661
Chris@16 662 //! <b>Effects</b>: Copy constructs a deque.
Chris@16 663 //!
Chris@16 664 //! <b>Postcondition</b>: x == *this.
Chris@16 665 //!
Chris@16 666 //! <b>Complexity</b>: Linear to the elements x contains.
Chris@16 667 deque(const deque& x)
Chris@16 668 : Base(allocator_traits_type::select_on_container_copy_construction(x.alloc()))
Chris@16 669 {
Chris@16 670 if(x.size()){
Chris@16 671 this->priv_initialize_map(x.size());
Chris@16 672 boost::container::uninitialized_copy_alloc
Chris@16 673 (this->alloc(), x.begin(), x.end(), this->members_.m_start);
Chris@16 674 }
Chris@16 675 }
Chris@16 676
Chris@101 677 //! <b>Effects</b>: Move constructor. Moves x's resources to *this.
Chris@16 678 //!
Chris@16 679 //! <b>Throws</b>: If allocator_type's copy constructor throws.
Chris@16 680 //!
Chris@16 681 //! <b>Complexity</b>: Constant.
Chris@16 682 deque(BOOST_RV_REF(deque) x)
Chris@101 683 : Base(BOOST_MOVE_BASE(Base, x))
Chris@16 684 { this->swap_members(x); }
Chris@16 685
Chris@16 686 //! <b>Effects</b>: Copy constructs a vector using the specified allocator.
Chris@16 687 //!
Chris@16 688 //! <b>Postcondition</b>: x == *this.
Chris@16 689 //!
Chris@16 690 //! <b>Throws</b>: If allocation
Chris@16 691 //! throws or T's copy constructor throws.
Chris@16 692 //!
Chris@16 693 //! <b>Complexity</b>: Linear to the elements x contains.
Chris@16 694 deque(const deque& x, const allocator_type &a)
Chris@16 695 : Base(a)
Chris@16 696 {
Chris@16 697 if(x.size()){
Chris@16 698 this->priv_initialize_map(x.size());
Chris@16 699 boost::container::uninitialized_copy_alloc
Chris@16 700 (this->alloc(), x.begin(), x.end(), this->members_.m_start);
Chris@16 701 }
Chris@16 702 }
Chris@16 703
Chris@16 704 //! <b>Effects</b>: Move constructor using the specified allocator.
Chris@101 705 //! Moves x's resources to *this if a == allocator_type().
Chris@16 706 //! Otherwise copies values from x to *this.
Chris@16 707 //!
Chris@16 708 //! <b>Throws</b>: If allocation or T's copy constructor throws.
Chris@16 709 //!
Chris@101 710 //! <b>Complexity</b>: Constant if a == x.get_allocator(), linear otherwise.
Chris@101 711 deque(BOOST_RV_REF(deque) x, const allocator_type &a)
Chris@16 712 : Base(a)
Chris@16 713 {
Chris@101 714 if(x.alloc() == a){
Chris@101 715 this->swap_members(x);
Chris@16 716 }
Chris@16 717 else{
Chris@101 718 if(x.size()){
Chris@101 719 this->priv_initialize_map(x.size());
Chris@16 720 boost::container::uninitialized_copy_alloc
Chris@101 721 ( this->alloc(), boost::make_move_iterator(x.begin())
Chris@101 722 , boost::make_move_iterator(x.end()), this->members_.m_start);
Chris@16 723 }
Chris@16 724 }
Chris@16 725 }
Chris@16 726
Chris@16 727 //! <b>Effects</b>: Destroys the deque. All stored values are destroyed
Chris@16 728 //! and used memory is deallocated.
Chris@16 729 //!
Chris@16 730 //! <b>Throws</b>: Nothing.
Chris@16 731 //!
Chris@16 732 //! <b>Complexity</b>: Linear to the number of elements.
Chris@101 733 ~deque() BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 734 {
Chris@16 735 this->priv_destroy_range(this->members_.m_start, this->members_.m_finish);
Chris@16 736 }
Chris@16 737
Chris@16 738 //! <b>Effects</b>: Makes *this contain the same elements as x.
Chris@16 739 //!
Chris@16 740 //! <b>Postcondition</b>: this->size() == x.size(). *this contains a copy
Chris@16 741 //! of each of x's elements.
Chris@16 742 //!
Chris@16 743 //! <b>Throws</b>: If memory allocation throws or T's copy constructor throws.
Chris@16 744 //!
Chris@16 745 //! <b>Complexity</b>: Linear to the number of elements in x.
Chris@16 746 deque& operator= (BOOST_COPY_ASSIGN_REF(deque) x)
Chris@16 747 {
Chris@16 748 if (&x != this){
Chris@16 749 allocator_type &this_alloc = this->alloc();
Chris@16 750 const allocator_type &x_alloc = x.alloc();
Chris@16 751 container_detail::bool_<allocator_traits_type::
Chris@16 752 propagate_on_container_copy_assignment::value> flag;
Chris@16 753 if(flag && this_alloc != x_alloc){
Chris@16 754 this->clear();
Chris@16 755 this->shrink_to_fit();
Chris@16 756 }
Chris@16 757 container_detail::assign_alloc(this->alloc(), x.alloc(), flag);
Chris@16 758 container_detail::assign_alloc(this->ptr_alloc(), x.ptr_alloc(), flag);
Chris@16 759 this->assign(x.cbegin(), x.cend());
Chris@16 760 }
Chris@16 761 return *this;
Chris@16 762 }
Chris@16 763
Chris@101 764 //! <b>Effects</b>: Move assignment. All x's values are transferred to *this.
Chris@16 765 //!
Chris@101 766 //! <b>Throws</b>: If allocator_traits_type::propagate_on_container_move_assignment
Chris@101 767 //! is false and (allocation throws or value_type's move constructor throws)
Chris@16 768 //!
Chris@101 769 //! <b>Complexity</b>: Constant if allocator_traits_type::
Chris@101 770 //! propagate_on_container_move_assignment is true or
Chris@101 771 //! this->get>allocator() == x.get_allocator(). Linear otherwise.
Chris@16 772 deque& operator= (BOOST_RV_REF(deque) x)
Chris@101 773 BOOST_NOEXCEPT_IF(allocator_traits_type::propagate_on_container_move_assignment::value
Chris@101 774 || allocator_traits_type::is_always_equal::value)
Chris@16 775 {
Chris@101 776 BOOST_ASSERT(this != &x);
Chris@101 777 allocator_type &this_alloc = this->alloc();
Chris@101 778 allocator_type &x_alloc = x.alloc();
Chris@101 779 const bool propagate_alloc = allocator_traits_type::
Chris@101 780 propagate_on_container_move_assignment::value;
Chris@101 781 container_detail::bool_<propagate_alloc> flag;
Chris@101 782 const bool allocators_equal = this_alloc == x_alloc; (void)allocators_equal;
Chris@101 783 //Resources can be transferred if both allocators are
Chris@101 784 //going to be equal after this function (either propagated or already equal)
Chris@101 785 if(propagate_alloc || allocators_equal){
Chris@101 786 //Destroy objects but retain memory in case x reuses it in the future
Chris@101 787 this->clear();
Chris@101 788 //Move allocator if needed
Chris@101 789 container_detail::move_alloc(this_alloc, x_alloc, flag);
Chris@101 790 container_detail::move_alloc(this->ptr_alloc(), x.ptr_alloc(), flag);
Chris@101 791 //Nothrow swap
Chris@101 792 this->swap_members(x);
Chris@101 793 }
Chris@101 794 //Else do a one by one move
Chris@101 795 else{
Chris@101 796 this->assign( boost::make_move_iterator(x.begin())
Chris@101 797 , boost::make_move_iterator(x.end()));
Chris@16 798 }
Chris@16 799 return *this;
Chris@16 800 }
Chris@16 801
Chris@101 802 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
Chris@101 803 //! <b>Effects</b>: Makes *this contain the same elements as il.
Chris@101 804 //!
Chris@101 805 //! <b>Postcondition</b>: this->size() == il.size(). *this contains a copy
Chris@101 806 //! of each of x's elements.
Chris@101 807 //!
Chris@101 808 //! <b>Throws</b>: If memory allocation throws or T's copy constructor throws.
Chris@101 809 //!
Chris@101 810 //! <b>Complexity</b>: Linear to the number of elements in il.
Chris@101 811 deque& operator=(std::initializer_list<value_type> il)
Chris@101 812 {
Chris@101 813 this->assign(il.begin(), il.end());
Chris@101 814 return *this;
Chris@101 815 }
Chris@101 816 #endif
Chris@101 817
Chris@16 818 //! <b>Effects</b>: Assigns the n copies of val to *this.
Chris@16 819 //!
Chris@16 820 //! <b>Throws</b>: If memory allocation throws or T's copy constructor throws.
Chris@16 821 //!
Chris@16 822 //! <b>Complexity</b>: Linear to n.
Chris@16 823 void assign(size_type n, const T& val)
Chris@16 824 {
Chris@16 825 typedef constant_iterator<value_type, difference_type> c_it;
Chris@16 826 this->assign(c_it(val, n), c_it());
Chris@16 827 }
Chris@16 828
Chris@16 829 //! <b>Effects</b>: Assigns the the range [first, last) to *this.
Chris@16 830 //!
Chris@16 831 //! <b>Throws</b>: If memory allocation throws or
Chris@16 832 //! T's constructor from dereferencing InIt throws.
Chris@16 833 //!
Chris@16 834 //! <b>Complexity</b>: Linear to n.
Chris@16 835 template <class InIt>
Chris@16 836 void assign(InIt first, InIt last
Chris@16 837 #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
Chris@16 838 , typename container_detail::enable_if_c
Chris@16 839 < !container_detail::is_convertible<InIt, size_type>::value
Chris@16 840 && container_detail::is_input_iterator<InIt>::value
Chris@16 841 >::type * = 0
Chris@16 842 #endif
Chris@16 843 )
Chris@16 844 {
Chris@16 845 iterator cur = this->begin();
Chris@16 846 for ( ; first != last && cur != end(); ++cur, ++first){
Chris@16 847 *cur = *first;
Chris@16 848 }
Chris@16 849 if (first == last){
Chris@16 850 this->erase(cur, this->cend());
Chris@16 851 }
Chris@16 852 else{
Chris@16 853 this->insert(this->cend(), first, last);
Chris@16 854 }
Chris@16 855 }
Chris@16 856
Chris@16 857 #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
Chris@16 858 template <class FwdIt>
Chris@16 859 void assign(FwdIt first, FwdIt last
Chris@16 860 , typename container_detail::enable_if_c
Chris@16 861 < !container_detail::is_convertible<FwdIt, size_type>::value
Chris@16 862 && !container_detail::is_input_iterator<FwdIt>::value
Chris@16 863 >::type * = 0
Chris@16 864 )
Chris@16 865 {
Chris@101 866 const size_type len = boost::container::iterator_distance(first, last);
Chris@16 867 if (len > size()) {
Chris@16 868 FwdIt mid = first;
Chris@101 869 boost::container::iterator_advance(mid, this->size());
Chris@16 870 boost::container::copy(first, mid, begin());
Chris@16 871 this->insert(this->cend(), mid, last);
Chris@16 872 }
Chris@16 873 else{
Chris@16 874 this->erase(boost::container::copy(first, last, this->begin()), cend());
Chris@16 875 }
Chris@16 876 }
Chris@16 877 #endif
Chris@16 878
Chris@101 879 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
Chris@101 880 //! <b>Effects</b>: Assigns the the range [il.begin(), il.end()) to *this.
Chris@101 881 //!
Chris@101 882 //! <b>Throws</b>: If memory allocation throws or
Chris@101 883 //! T's constructor from dereferencing std::initializer_list iterator throws.
Chris@101 884 //!
Chris@101 885 //! <b>Complexity</b>: Linear to il.size().
Chris@101 886 void assign(std::initializer_list<value_type> il)
Chris@101 887 { this->assign(il.begin(), il.end()); }
Chris@101 888 #endif
Chris@101 889
Chris@16 890 //! <b>Effects</b>: Returns a copy of the internal allocator.
Chris@16 891 //!
Chris@16 892 //! <b>Throws</b>: If allocator's copy constructor throws.
Chris@16 893 //!
Chris@16 894 //! <b>Complexity</b>: Constant.
Chris@101 895 allocator_type get_allocator() const BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 896 { return Base::alloc(); }
Chris@16 897
Chris@16 898 //! <b>Effects</b>: Returns a reference to the internal allocator.
Chris@16 899 //!
Chris@16 900 //! <b>Throws</b>: Nothing
Chris@16 901 //!
Chris@16 902 //! <b>Complexity</b>: Constant.
Chris@16 903 //!
Chris@16 904 //! <b>Note</b>: Non-standard extension.
Chris@101 905 const stored_allocator_type &get_stored_allocator() const BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 906 { return Base::alloc(); }
Chris@16 907
Chris@16 908 //////////////////////////////////////////////
Chris@16 909 //
Chris@16 910 // iterators
Chris@16 911 //
Chris@16 912 //////////////////////////////////////////////
Chris@16 913
Chris@16 914 //! <b>Effects</b>: Returns a reference to the internal allocator.
Chris@16 915 //!
Chris@16 916 //! <b>Throws</b>: Nothing
Chris@16 917 //!
Chris@16 918 //! <b>Complexity</b>: Constant.
Chris@16 919 //!
Chris@16 920 //! <b>Note</b>: Non-standard extension.
Chris@101 921 stored_allocator_type &get_stored_allocator() BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 922 { return Base::alloc(); }
Chris@16 923
Chris@16 924 //! <b>Effects</b>: Returns an iterator to the first element contained in the deque.
Chris@16 925 //!
Chris@16 926 //! <b>Throws</b>: Nothing.
Chris@16 927 //!
Chris@16 928 //! <b>Complexity</b>: Constant.
Chris@101 929 iterator begin() BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 930 { return this->members_.m_start; }
Chris@16 931
Chris@16 932 //! <b>Effects</b>: Returns a const_iterator to the first element contained in the deque.
Chris@16 933 //!
Chris@16 934 //! <b>Throws</b>: Nothing.
Chris@16 935 //!
Chris@16 936 //! <b>Complexity</b>: Constant.
Chris@101 937 const_iterator begin() const BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 938 { return this->members_.m_start; }
Chris@16 939
Chris@16 940 //! <b>Effects</b>: Returns an iterator to the end of the deque.
Chris@16 941 //!
Chris@16 942 //! <b>Throws</b>: Nothing.
Chris@16 943 //!
Chris@16 944 //! <b>Complexity</b>: Constant.
Chris@101 945 iterator end() BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 946 { return this->members_.m_finish; }
Chris@16 947
Chris@16 948 //! <b>Effects</b>: Returns a const_iterator to the end of the deque.
Chris@16 949 //!
Chris@16 950 //! <b>Throws</b>: Nothing.
Chris@16 951 //!
Chris@16 952 //! <b>Complexity</b>: Constant.
Chris@101 953 const_iterator end() const BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 954 { return this->members_.m_finish; }
Chris@16 955
Chris@16 956 //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning
Chris@16 957 //! of the reversed deque.
Chris@16 958 //!
Chris@16 959 //! <b>Throws</b>: Nothing.
Chris@16 960 //!
Chris@16 961 //! <b>Complexity</b>: Constant.
Chris@101 962 reverse_iterator rbegin() BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 963 { return reverse_iterator(this->members_.m_finish); }
Chris@16 964
Chris@16 965 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
Chris@16 966 //! of the reversed deque.
Chris@16 967 //!
Chris@16 968 //! <b>Throws</b>: Nothing.
Chris@16 969 //!
Chris@16 970 //! <b>Complexity</b>: Constant.
Chris@101 971 const_reverse_iterator rbegin() const BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 972 { return const_reverse_iterator(this->members_.m_finish); }
Chris@16 973
Chris@16 974 //! <b>Effects</b>: Returns a reverse_iterator pointing to the end
Chris@16 975 //! of the reversed deque.
Chris@16 976 //!
Chris@16 977 //! <b>Throws</b>: Nothing.
Chris@16 978 //!
Chris@16 979 //! <b>Complexity</b>: Constant.
Chris@101 980 reverse_iterator rend() BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 981 { return reverse_iterator(this->members_.m_start); }
Chris@16 982
Chris@16 983 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
Chris@16 984 //! of the reversed deque.
Chris@16 985 //!
Chris@16 986 //! <b>Throws</b>: Nothing.
Chris@16 987 //!
Chris@16 988 //! <b>Complexity</b>: Constant.
Chris@101 989 const_reverse_iterator rend() const BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 990 { return const_reverse_iterator(this->members_.m_start); }
Chris@16 991
Chris@16 992 //! <b>Effects</b>: Returns a const_iterator to the first element contained in the deque.
Chris@16 993 //!
Chris@16 994 //! <b>Throws</b>: Nothing.
Chris@16 995 //!
Chris@16 996 //! <b>Complexity</b>: Constant.
Chris@101 997 const_iterator cbegin() const BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 998 { return this->members_.m_start; }
Chris@16 999
Chris@16 1000 //! <b>Effects</b>: Returns a const_iterator to the end of the deque.
Chris@16 1001 //!
Chris@16 1002 //! <b>Throws</b>: Nothing.
Chris@16 1003 //!
Chris@16 1004 //! <b>Complexity</b>: Constant.
Chris@101 1005 const_iterator cend() const BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 1006 { return this->members_.m_finish; }
Chris@16 1007
Chris@16 1008 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
Chris@16 1009 //! of the reversed deque.
Chris@16 1010 //!
Chris@16 1011 //! <b>Throws</b>: Nothing.
Chris@16 1012 //!
Chris@16 1013 //! <b>Complexity</b>: Constant.
Chris@101 1014 const_reverse_iterator crbegin() const BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 1015 { return const_reverse_iterator(this->members_.m_finish); }
Chris@16 1016
Chris@16 1017 //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
Chris@16 1018 //! of the reversed deque.
Chris@16 1019 //!
Chris@16 1020 //! <b>Throws</b>: Nothing.
Chris@16 1021 //!
Chris@16 1022 //! <b>Complexity</b>: Constant.
Chris@101 1023 const_reverse_iterator crend() const BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 1024 { return const_reverse_iterator(this->members_.m_start); }
Chris@16 1025
Chris@16 1026 //////////////////////////////////////////////
Chris@16 1027 //
Chris@16 1028 // capacity
Chris@16 1029 //
Chris@16 1030 //////////////////////////////////////////////
Chris@16 1031
Chris@16 1032 //! <b>Effects</b>: Returns true if the deque contains no elements.
Chris@16 1033 //!
Chris@16 1034 //! <b>Throws</b>: Nothing.
Chris@16 1035 //!
Chris@16 1036 //! <b>Complexity</b>: Constant.
Chris@101 1037 bool empty() const BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 1038 { return this->members_.m_finish == this->members_.m_start; }
Chris@16 1039
Chris@16 1040 //! <b>Effects</b>: Returns the number of the elements contained in the deque.
Chris@16 1041 //!
Chris@16 1042 //! <b>Throws</b>: Nothing.
Chris@16 1043 //!
Chris@16 1044 //! <b>Complexity</b>: Constant.
Chris@101 1045 size_type size() const BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 1046 { return this->members_.m_finish - this->members_.m_start; }
Chris@16 1047
Chris@16 1048 //! <b>Effects</b>: Returns the largest possible size of the deque.
Chris@16 1049 //!
Chris@16 1050 //! <b>Throws</b>: Nothing.
Chris@16 1051 //!
Chris@16 1052 //! <b>Complexity</b>: Constant.
Chris@101 1053 size_type max_size() const BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 1054 { return allocator_traits_type::max_size(this->alloc()); }
Chris@16 1055
Chris@16 1056 //! <b>Effects</b>: Inserts or erases elements at the end such that
Chris@16 1057 //! the size becomes n. New elements are value initialized.
Chris@16 1058 //!
Chris@16 1059 //! <b>Throws</b>: If memory allocation throws, or T's constructor throws.
Chris@16 1060 //!
Chris@16 1061 //! <b>Complexity</b>: Linear to the difference between size() and new_size.
Chris@16 1062 void resize(size_type new_size)
Chris@16 1063 {
Chris@16 1064 const size_type len = size();
Chris@16 1065 if (new_size < len)
Chris@16 1066 this->priv_erase_last_n(len - new_size);
Chris@16 1067 else{
Chris@16 1068 const size_type n = new_size - this->size();
Chris@101 1069 container_detail::insert_value_initialized_n_proxy<Allocator, iterator> proxy;
Chris@16 1070 priv_insert_back_aux_impl(n, proxy);
Chris@16 1071 }
Chris@16 1072 }
Chris@16 1073
Chris@16 1074 //! <b>Effects</b>: Inserts or erases elements at the end such that
Chris@16 1075 //! the size becomes n. New elements are default initialized.
Chris@16 1076 //!
Chris@16 1077 //! <b>Throws</b>: If memory allocation throws, or T's constructor throws.
Chris@16 1078 //!
Chris@16 1079 //! <b>Complexity</b>: Linear to the difference between size() and new_size.
Chris@16 1080 //!
Chris@16 1081 //! <b>Note</b>: Non-standard extension
Chris@16 1082 void resize(size_type new_size, default_init_t)
Chris@16 1083 {
Chris@16 1084 const size_type len = size();
Chris@16 1085 if (new_size < len)
Chris@16 1086 this->priv_erase_last_n(len - new_size);
Chris@16 1087 else{
Chris@16 1088 const size_type n = new_size - this->size();
Chris@101 1089 container_detail::insert_default_initialized_n_proxy<Allocator, iterator> proxy;
Chris@16 1090 priv_insert_back_aux_impl(n, proxy);
Chris@16 1091 }
Chris@16 1092 }
Chris@16 1093
Chris@16 1094 //! <b>Effects</b>: Inserts or erases elements at the end such that
Chris@16 1095 //! the size becomes n. New elements are copy constructed from x.
Chris@16 1096 //!
Chris@16 1097 //! <b>Throws</b>: If memory allocation throws, or T's copy constructor throws.
Chris@16 1098 //!
Chris@16 1099 //! <b>Complexity</b>: Linear to the difference between size() and new_size.
Chris@16 1100 void resize(size_type new_size, const value_type& x)
Chris@16 1101 {
Chris@16 1102 const size_type len = size();
Chris@16 1103 if (new_size < len)
Chris@16 1104 this->erase(this->members_.m_start + new_size, this->members_.m_finish);
Chris@16 1105 else
Chris@16 1106 this->insert(this->members_.m_finish, new_size - len, x);
Chris@16 1107 }
Chris@16 1108
Chris@16 1109 //! <b>Effects</b>: Tries to deallocate the excess of memory created
Chris@16 1110 //! with previous allocations. The size of the deque is unchanged
Chris@16 1111 //!
Chris@16 1112 //! <b>Throws</b>: If memory allocation throws.
Chris@16 1113 //!
Chris@16 1114 //! <b>Complexity</b>: Constant.
Chris@16 1115 void shrink_to_fit()
Chris@16 1116 {
Chris@16 1117 //This deque implementation already
Chris@16 1118 //deallocates excess nodes when erasing
Chris@16 1119 //so there is nothing to do except for
Chris@16 1120 //empty deque
Chris@16 1121 if(this->empty()){
Chris@16 1122 this->priv_clear_map();
Chris@16 1123 }
Chris@16 1124 }
Chris@16 1125
Chris@16 1126 //////////////////////////////////////////////
Chris@16 1127 //
Chris@16 1128 // element access
Chris@16 1129 //
Chris@16 1130 //////////////////////////////////////////////
Chris@16 1131
Chris@16 1132 //! <b>Requires</b>: !empty()
Chris@16 1133 //!
Chris@16 1134 //! <b>Effects</b>: Returns a reference to the first
Chris@16 1135 //! element of the container.
Chris@16 1136 //!
Chris@16 1137 //! <b>Throws</b>: Nothing.
Chris@16 1138 //!
Chris@16 1139 //! <b>Complexity</b>: Constant.
Chris@101 1140 reference front() BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 1141 { return *this->members_.m_start; }
Chris@16 1142
Chris@16 1143 //! <b>Requires</b>: !empty()
Chris@16 1144 //!
Chris@16 1145 //! <b>Effects</b>: Returns a const reference to the first element
Chris@16 1146 //! from the beginning of the container.
Chris@16 1147 //!
Chris@16 1148 //! <b>Throws</b>: Nothing.
Chris@16 1149 //!
Chris@16 1150 //! <b>Complexity</b>: Constant.
Chris@101 1151 const_reference front() const BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 1152 { return *this->members_.m_start; }
Chris@16 1153
Chris@16 1154 //! <b>Requires</b>: !empty()
Chris@16 1155 //!
Chris@16 1156 //! <b>Effects</b>: Returns a reference to the last
Chris@16 1157 //! element of the container.
Chris@16 1158 //!
Chris@16 1159 //! <b>Throws</b>: Nothing.
Chris@16 1160 //!
Chris@16 1161 //! <b>Complexity</b>: Constant.
Chris@101 1162 reference back() BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 1163 { return *(end()-1); }
Chris@16 1164
Chris@16 1165 //! <b>Requires</b>: !empty()
Chris@16 1166 //!
Chris@16 1167 //! <b>Effects</b>: Returns a const reference to the last
Chris@16 1168 //! element of the container.
Chris@16 1169 //!
Chris@16 1170 //! <b>Throws</b>: Nothing.
Chris@16 1171 //!
Chris@16 1172 //! <b>Complexity</b>: Constant.
Chris@101 1173 const_reference back() const BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 1174 { return *(cend()-1); }
Chris@16 1175
Chris@16 1176 //! <b>Requires</b>: size() > n.
Chris@16 1177 //!
Chris@16 1178 //! <b>Effects</b>: Returns a reference to the nth element
Chris@16 1179 //! from the beginning of the container.
Chris@16 1180 //!
Chris@16 1181 //! <b>Throws</b>: Nothing.
Chris@16 1182 //!
Chris@16 1183 //! <b>Complexity</b>: Constant.
Chris@101 1184 reference operator[](size_type n) BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 1185 { return this->members_.m_start[difference_type(n)]; }
Chris@16 1186
Chris@16 1187 //! <b>Requires</b>: size() > n.
Chris@16 1188 //!
Chris@16 1189 //! <b>Effects</b>: Returns a const reference to the nth element
Chris@16 1190 //! from the beginning of the container.
Chris@16 1191 //!
Chris@16 1192 //! <b>Throws</b>: Nothing.
Chris@16 1193 //!
Chris@16 1194 //! <b>Complexity</b>: Constant.
Chris@101 1195 const_reference operator[](size_type n) const BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 1196 { return this->members_.m_start[difference_type(n)]; }
Chris@16 1197
Chris@101 1198 //! <b>Requires</b>: size() >= n.
Chris@101 1199 //!
Chris@101 1200 //! <b>Effects</b>: Returns an iterator to the nth element
Chris@101 1201 //! from the beginning of the container. Returns end()
Chris@101 1202 //! if n == size().
Chris@101 1203 //!
Chris@101 1204 //! <b>Throws</b>: Nothing.
Chris@101 1205 //!
Chris@101 1206 //! <b>Complexity</b>: Constant.
Chris@101 1207 //!
Chris@101 1208 //! <b>Note</b>: Non-standard extension
Chris@101 1209 iterator nth(size_type n) BOOST_NOEXCEPT_OR_NOTHROW
Chris@101 1210 {
Chris@101 1211 BOOST_ASSERT(this->size() >= n);
Chris@101 1212 return iterator(this->begin()+n);
Chris@101 1213 }
Chris@101 1214
Chris@101 1215 //! <b>Requires</b>: size() >= n.
Chris@101 1216 //!
Chris@101 1217 //! <b>Effects</b>: Returns a const_iterator to the nth element
Chris@101 1218 //! from the beginning of the container. Returns end()
Chris@101 1219 //! if n == size().
Chris@101 1220 //!
Chris@101 1221 //! <b>Throws</b>: Nothing.
Chris@101 1222 //!
Chris@101 1223 //! <b>Complexity</b>: Constant.
Chris@101 1224 //!
Chris@101 1225 //! <b>Note</b>: Non-standard extension
Chris@101 1226 const_iterator nth(size_type n) const BOOST_NOEXCEPT_OR_NOTHROW
Chris@101 1227 {
Chris@101 1228 BOOST_ASSERT(this->size() >= n);
Chris@101 1229 return const_iterator(this->cbegin()+n);
Chris@101 1230 }
Chris@101 1231
Chris@101 1232 //! <b>Requires</b>: size() >= n.
Chris@101 1233 //!
Chris@101 1234 //! <b>Effects</b>: Returns an iterator to the nth element
Chris@101 1235 //! from the beginning of the container. Returns end()
Chris@101 1236 //! if n == size().
Chris@101 1237 //!
Chris@101 1238 //! <b>Throws</b>: Nothing.
Chris@101 1239 //!
Chris@101 1240 //! <b>Complexity</b>: Constant.
Chris@101 1241 //!
Chris@101 1242 //! <b>Note</b>: Non-standard extension
Chris@101 1243 size_type index_of(iterator p) BOOST_NOEXCEPT_OR_NOTHROW
Chris@101 1244 { return this->priv_index_of(p); }
Chris@101 1245
Chris@101 1246 //! <b>Requires</b>: begin() <= p <= end().
Chris@101 1247 //!
Chris@101 1248 //! <b>Effects</b>: Returns the index of the element pointed by p
Chris@101 1249 //! and size() if p == end().
Chris@101 1250 //!
Chris@101 1251 //! <b>Throws</b>: Nothing.
Chris@101 1252 //!
Chris@101 1253 //! <b>Complexity</b>: Constant.
Chris@101 1254 //!
Chris@101 1255 //! <b>Note</b>: Non-standard extension
Chris@101 1256 size_type index_of(const_iterator p) const BOOST_NOEXCEPT_OR_NOTHROW
Chris@101 1257 { return this->priv_index_of(p); }
Chris@101 1258
Chris@16 1259 //! <b>Requires</b>: size() > n.
Chris@16 1260 //!
Chris@16 1261 //! <b>Effects</b>: Returns a reference to the nth element
Chris@16 1262 //! from the beginning of the container.
Chris@16 1263 //!
Chris@16 1264 //! <b>Throws</b>: std::range_error if n >= size()
Chris@16 1265 //!
Chris@16 1266 //! <b>Complexity</b>: Constant.
Chris@16 1267 reference at(size_type n)
Chris@16 1268 { this->priv_range_check(n); return (*this)[n]; }
Chris@16 1269
Chris@16 1270 //! <b>Requires</b>: size() > n.
Chris@16 1271 //!
Chris@16 1272 //! <b>Effects</b>: Returns a const reference to the nth element
Chris@16 1273 //! from the beginning of the container.
Chris@16 1274 //!
Chris@16 1275 //! <b>Throws</b>: std::range_error if n >= size()
Chris@16 1276 //!
Chris@16 1277 //! <b>Complexity</b>: Constant.
Chris@16 1278 const_reference at(size_type n) const
Chris@16 1279 { this->priv_range_check(n); return (*this)[n]; }
Chris@16 1280
Chris@16 1281 //////////////////////////////////////////////
Chris@16 1282 //
Chris@16 1283 // modifiers
Chris@16 1284 //
Chris@16 1285 //////////////////////////////////////////////
Chris@16 1286
Chris@101 1287 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
Chris@16 1288
Chris@16 1289 //! <b>Effects</b>: Inserts an object of type T constructed with
Chris@16 1290 //! std::forward<Args>(args)... in the beginning of the deque.
Chris@16 1291 //!
Chris@16 1292 //! <b>Throws</b>: If memory allocation throws or the in-place constructor throws.
Chris@16 1293 //!
Chris@16 1294 //! <b>Complexity</b>: Amortized constant time
Chris@16 1295 template <class... Args>
Chris@101 1296 void emplace_front(BOOST_FWD_REF(Args)... args)
Chris@16 1297 {
Chris@16 1298 if(this->priv_push_front_simple_available()){
Chris@16 1299 allocator_traits_type::construct
Chris@16 1300 ( this->alloc()
Chris@16 1301 , this->priv_push_front_simple_pos()
Chris@16 1302 , boost::forward<Args>(args)...);
Chris@16 1303 this->priv_push_front_simple_commit();
Chris@16 1304 }
Chris@16 1305 else{
Chris@101 1306 typedef container_detail::insert_nonmovable_emplace_proxy<Allocator, iterator, Args...> type;
Chris@101 1307 this->priv_insert_front_aux_impl(1, type(boost::forward<Args>(args)...));
Chris@16 1308 }
Chris@16 1309 }
Chris@16 1310
Chris@16 1311 //! <b>Effects</b>: Inserts an object of type T constructed with
Chris@16 1312 //! std::forward<Args>(args)... in the end of the deque.
Chris@16 1313 //!
Chris@16 1314 //! <b>Throws</b>: If memory allocation throws or the in-place constructor throws.
Chris@16 1315 //!
Chris@16 1316 //! <b>Complexity</b>: Amortized constant time
Chris@16 1317 template <class... Args>
Chris@101 1318 void emplace_back(BOOST_FWD_REF(Args)... args)
Chris@16 1319 {
Chris@16 1320 if(this->priv_push_back_simple_available()){
Chris@16 1321 allocator_traits_type::construct
Chris@16 1322 ( this->alloc()
Chris@16 1323 , this->priv_push_back_simple_pos()
Chris@16 1324 , boost::forward<Args>(args)...);
Chris@16 1325 this->priv_push_back_simple_commit();
Chris@16 1326 }
Chris@16 1327 else{
Chris@101 1328 typedef container_detail::insert_nonmovable_emplace_proxy<Allocator, iterator, Args...> type;
Chris@101 1329 this->priv_insert_back_aux_impl(1, type(boost::forward<Args>(args)...));
Chris@16 1330 }
Chris@16 1331 }
Chris@16 1332
Chris@101 1333 //! <b>Requires</b>: p must be a valid iterator of *this.
Chris@16 1334 //!
Chris@16 1335 //! <b>Effects</b>: Inserts an object of type T constructed with
Chris@101 1336 //! std::forward<Args>(args)... before p
Chris@16 1337 //!
Chris@16 1338 //! <b>Throws</b>: If memory allocation throws or the in-place constructor throws.
Chris@16 1339 //!
Chris@101 1340 //! <b>Complexity</b>: If p is end(), amortized constant time
Chris@16 1341 //! Linear time otherwise.
Chris@16 1342 template <class... Args>
Chris@101 1343 iterator emplace(const_iterator p, BOOST_FWD_REF(Args)... args)
Chris@16 1344 {
Chris@16 1345 if(p == this->cbegin()){
Chris@16 1346 this->emplace_front(boost::forward<Args>(args)...);
Chris@16 1347 return this->begin();
Chris@16 1348 }
Chris@16 1349 else if(p == this->cend()){
Chris@16 1350 this->emplace_back(boost::forward<Args>(args)...);
Chris@16 1351 return (this->end()-1);
Chris@16 1352 }
Chris@16 1353 else{
Chris@16 1354 typedef container_detail::insert_emplace_proxy<Allocator, iterator, Args...> type;
Chris@101 1355 return this->priv_insert_aux_impl(p, 1, type(boost::forward<Args>(args)...));
Chris@16 1356 }
Chris@16 1357 }
Chris@16 1358
Chris@101 1359 #else //!defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
Chris@16 1360
Chris@101 1361 #define BOOST_CONTAINER_DEQUE_EMPLACE_CODE(N) \
Chris@101 1362 BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N\
Chris@101 1363 void emplace_front(BOOST_MOVE_UREF##N)\
Chris@101 1364 {\
Chris@101 1365 if(priv_push_front_simple_available()){\
Chris@101 1366 allocator_traits_type::construct\
Chris@101 1367 ( this->alloc(), this->priv_push_front_simple_pos() BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\
Chris@101 1368 priv_push_front_simple_commit();\
Chris@101 1369 }\
Chris@101 1370 else{\
Chris@101 1371 typedef container_detail::insert_nonmovable_emplace_proxy##N\
Chris@101 1372 <Allocator, iterator BOOST_MOVE_I##N BOOST_MOVE_TARG##N> type;\
Chris@101 1373 priv_insert_front_aux_impl(1, type(BOOST_MOVE_FWD##N));\
Chris@101 1374 }\
Chris@101 1375 }\
Chris@101 1376 \
Chris@101 1377 BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N\
Chris@101 1378 void emplace_back(BOOST_MOVE_UREF##N)\
Chris@101 1379 {\
Chris@101 1380 if(priv_push_back_simple_available()){\
Chris@101 1381 allocator_traits_type::construct\
Chris@101 1382 ( this->alloc(), this->priv_push_back_simple_pos() BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\
Chris@101 1383 priv_push_back_simple_commit();\
Chris@101 1384 }\
Chris@101 1385 else{\
Chris@101 1386 typedef container_detail::insert_nonmovable_emplace_proxy##N\
Chris@101 1387 <Allocator, iterator BOOST_MOVE_I##N BOOST_MOVE_TARG##N> type;\
Chris@101 1388 priv_insert_back_aux_impl(1, type(BOOST_MOVE_FWD##N));\
Chris@101 1389 }\
Chris@101 1390 }\
Chris@101 1391 \
Chris@101 1392 BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N\
Chris@101 1393 iterator emplace(const_iterator p BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
Chris@101 1394 {\
Chris@101 1395 if(p == this->cbegin()){\
Chris@101 1396 this->emplace_front(BOOST_MOVE_FWD##N);\
Chris@101 1397 return this->begin();\
Chris@101 1398 }\
Chris@101 1399 else if(p == cend()){\
Chris@101 1400 this->emplace_back(BOOST_MOVE_FWD##N);\
Chris@101 1401 return (--this->end());\
Chris@101 1402 }\
Chris@101 1403 else{\
Chris@101 1404 typedef container_detail::insert_emplace_proxy_arg##N\
Chris@101 1405 <Allocator, iterator BOOST_MOVE_I##N BOOST_MOVE_TARG##N> type;\
Chris@101 1406 return this->priv_insert_aux_impl(p, 1, type(BOOST_MOVE_FWD##N));\
Chris@101 1407 }\
Chris@101 1408 }
Chris@101 1409 //
Chris@101 1410 BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_DEQUE_EMPLACE_CODE)
Chris@101 1411 #undef BOOST_CONTAINER_DEQUE_EMPLACE_CODE
Chris@16 1412
Chris@101 1413 #endif // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
Chris@16 1414
Chris@16 1415 #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
Chris@16 1416 //! <b>Effects</b>: Inserts a copy of x at the front of the deque.
Chris@16 1417 //!
Chris@16 1418 //! <b>Throws</b>: If memory allocation throws or
Chris@16 1419 //! T's copy constructor throws.
Chris@16 1420 //!
Chris@16 1421 //! <b>Complexity</b>: Amortized constant time.
Chris@16 1422 void push_front(const T &x);
Chris@16 1423
Chris@16 1424 //! <b>Effects</b>: Constructs a new element in the front of the deque
Chris@101 1425 //! and moves the resources of x to this new element.
Chris@16 1426 //!
Chris@16 1427 //! <b>Throws</b>: If memory allocation throws.
Chris@16 1428 //!
Chris@16 1429 //! <b>Complexity</b>: Amortized constant time.
Chris@16 1430 void push_front(T &&x);
Chris@16 1431 #else
Chris@16 1432 BOOST_MOVE_CONVERSION_AWARE_CATCH(push_front, T, void, priv_push_front)
Chris@16 1433 #endif
Chris@16 1434
Chris@16 1435 #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
Chris@16 1436 //! <b>Effects</b>: Inserts a copy of x at the end of the deque.
Chris@16 1437 //!
Chris@16 1438 //! <b>Throws</b>: If memory allocation throws or
Chris@16 1439 //! T's copy constructor throws.
Chris@16 1440 //!
Chris@16 1441 //! <b>Complexity</b>: Amortized constant time.
Chris@16 1442 void push_back(const T &x);
Chris@16 1443
Chris@16 1444 //! <b>Effects</b>: Constructs a new element in the end of the deque
Chris@101 1445 //! and moves the resources of x to this new element.
Chris@16 1446 //!
Chris@16 1447 //! <b>Throws</b>: If memory allocation throws.
Chris@16 1448 //!
Chris@16 1449 //! <b>Complexity</b>: Amortized constant time.
Chris@16 1450 void push_back(T &&x);
Chris@16 1451 #else
Chris@16 1452 BOOST_MOVE_CONVERSION_AWARE_CATCH(push_back, T, void, priv_push_back)
Chris@16 1453 #endif
Chris@16 1454
Chris@16 1455 #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
Chris@16 1456
Chris@101 1457 //! <b>Requires</b>: p must be a valid iterator of *this.
Chris@16 1458 //!
Chris@101 1459 //! <b>Effects</b>: Insert a copy of x before p.
Chris@16 1460 //!
Chris@16 1461 //! <b>Returns</b>: an iterator to the inserted element.
Chris@16 1462 //!
Chris@16 1463 //! <b>Throws</b>: If memory allocation throws or x's copy constructor throws.
Chris@16 1464 //!
Chris@101 1465 //! <b>Complexity</b>: If p is end(), amortized constant time
Chris@16 1466 //! Linear time otherwise.
Chris@101 1467 iterator insert(const_iterator p, const T &x);
Chris@16 1468
Chris@101 1469 //! <b>Requires</b>: p must be a valid iterator of *this.
Chris@16 1470 //!
Chris@101 1471 //! <b>Effects</b>: Insert a new element before p with x's resources.
Chris@16 1472 //!
Chris@16 1473 //! <b>Returns</b>: an iterator to the inserted element.
Chris@16 1474 //!
Chris@16 1475 //! <b>Throws</b>: If memory allocation throws.
Chris@16 1476 //!
Chris@101 1477 //! <b>Complexity</b>: If p is end(), amortized constant time
Chris@16 1478 //! Linear time otherwise.
Chris@101 1479 iterator insert(const_iterator p, T &&x);
Chris@16 1480 #else
Chris@16 1481 BOOST_MOVE_CONVERSION_AWARE_CATCH_1ARG(insert, T, iterator, priv_insert, const_iterator, const_iterator)
Chris@16 1482 #endif
Chris@16 1483
Chris@16 1484 //! <b>Requires</b>: pos must be a valid iterator of *this.
Chris@16 1485 //!
Chris@16 1486 //! <b>Effects</b>: Insert n copies of x before pos.
Chris@16 1487 //!
Chris@16 1488 //! <b>Returns</b>: an iterator to the first inserted element or pos if n is 0.
Chris@16 1489 //!
Chris@16 1490 //! <b>Throws</b>: If memory allocation throws or T's copy constructor throws.
Chris@16 1491 //!
Chris@16 1492 //! <b>Complexity</b>: Linear to n.
Chris@16 1493 iterator insert(const_iterator pos, size_type n, const value_type& x)
Chris@16 1494 {
Chris@16 1495 typedef constant_iterator<value_type, difference_type> c_it;
Chris@16 1496 return this->insert(pos, c_it(x, n), c_it());
Chris@16 1497 }
Chris@16 1498
Chris@16 1499 //! <b>Requires</b>: pos must be a valid iterator of *this.
Chris@16 1500 //!
Chris@16 1501 //! <b>Effects</b>: Insert a copy of the [first, last) range before pos.
Chris@16 1502 //!
Chris@16 1503 //! <b>Returns</b>: an iterator to the first inserted element or pos if first == last.
Chris@16 1504 //!
Chris@16 1505 //! <b>Throws</b>: If memory allocation throws, T's constructor from a
Chris@16 1506 //! dereferenced InIt throws or T's copy constructor throws.
Chris@16 1507 //!
Chris@101 1508 //! <b>Complexity</b>: Linear to distance [first, last).
Chris@16 1509 template <class InIt>
Chris@16 1510 iterator insert(const_iterator pos, InIt first, InIt last
Chris@16 1511 #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
Chris@16 1512 , typename container_detail::enable_if_c
Chris@16 1513 < !container_detail::is_convertible<InIt, size_type>::value
Chris@16 1514 && container_detail::is_input_iterator<InIt>::value
Chris@16 1515 >::type * = 0
Chris@16 1516 #endif
Chris@16 1517 )
Chris@16 1518 {
Chris@16 1519 size_type n = 0;
Chris@16 1520 iterator it(pos.unconst());
Chris@16 1521 for(;first != last; ++first, ++n){
Chris@16 1522 it = this->emplace(it, *first);
Chris@16 1523 ++it;
Chris@16 1524 }
Chris@16 1525 it -= n;
Chris@16 1526 return it;
Chris@16 1527 }
Chris@16 1528
Chris@101 1529 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
Chris@101 1530 //! <b>Requires</b>: pos must be a valid iterator of *this.
Chris@101 1531 //!
Chris@101 1532 //! <b>Effects</b>: Insert a copy of the [il.begin(), il.end()) range before pos.
Chris@101 1533 //!
Chris@101 1534 //! <b>Returns</b>: an iterator to the first inserted element or pos if il.begin() == il.end().
Chris@101 1535 //!
Chris@101 1536 //! <b>Throws</b>: If memory allocation throws, T's constructor from a
Chris@101 1537 //! dereferenced std::initializer_list throws or T's copy constructor throws.
Chris@101 1538 //!
Chris@101 1539 //! <b>Complexity</b>: Linear to distance [il.begin(), il.end()).
Chris@101 1540 iterator insert(const_iterator pos, std::initializer_list<value_type> il)
Chris@101 1541 { return insert(pos, il.begin(), il.end()); }
Chris@101 1542 #endif
Chris@101 1543
Chris@16 1544 #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
Chris@16 1545 template <class FwdIt>
Chris@16 1546 iterator insert(const_iterator p, FwdIt first, FwdIt last
Chris@16 1547 #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
Chris@16 1548 , typename container_detail::enable_if_c
Chris@16 1549 < !container_detail::is_convertible<FwdIt, size_type>::value
Chris@16 1550 && !container_detail::is_input_iterator<FwdIt>::value
Chris@16 1551 >::type * = 0
Chris@16 1552 #endif
Chris@16 1553 )
Chris@16 1554 {
Chris@101 1555 container_detail::insert_range_proxy<Allocator, FwdIt, iterator> proxy(first);
Chris@101 1556 return priv_insert_aux_impl(p, boost::container::iterator_distance(first, last), proxy);
Chris@16 1557 }
Chris@16 1558 #endif
Chris@16 1559
Chris@16 1560 //! <b>Effects</b>: Removes the first element from the deque.
Chris@16 1561 //!
Chris@16 1562 //! <b>Throws</b>: Nothing.
Chris@16 1563 //!
Chris@16 1564 //! <b>Complexity</b>: Constant time.
Chris@101 1565 void pop_front() BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 1566 {
Chris@16 1567 if (this->members_.m_start.m_cur != this->members_.m_start.m_last - 1) {
Chris@16 1568 allocator_traits_type::destroy
Chris@16 1569 ( this->alloc()
Chris@16 1570 , container_detail::to_raw_pointer(this->members_.m_start.m_cur)
Chris@16 1571 );
Chris@16 1572 ++this->members_.m_start.m_cur;
Chris@16 1573 }
Chris@16 1574 else
Chris@16 1575 this->priv_pop_front_aux();
Chris@16 1576 }
Chris@16 1577
Chris@16 1578 //! <b>Effects</b>: Removes the last element from the deque.
Chris@16 1579 //!
Chris@16 1580 //! <b>Throws</b>: Nothing.
Chris@16 1581 //!
Chris@16 1582 //! <b>Complexity</b>: Constant time.
Chris@101 1583 void pop_back() BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 1584 {
Chris@16 1585 if (this->members_.m_finish.m_cur != this->members_.m_finish.m_first) {
Chris@16 1586 --this->members_.m_finish.m_cur;
Chris@16 1587 allocator_traits_type::destroy
Chris@16 1588 ( this->alloc()
Chris@16 1589 , container_detail::to_raw_pointer(this->members_.m_finish.m_cur)
Chris@16 1590 );
Chris@16 1591 }
Chris@16 1592 else
Chris@16 1593 this->priv_pop_back_aux();
Chris@16 1594 }
Chris@16 1595
Chris@101 1596 //! <b>Effects</b>: Erases the element at p.
Chris@16 1597 //!
Chris@16 1598 //! <b>Throws</b>: Nothing.
Chris@16 1599 //!
Chris@16 1600 //! <b>Complexity</b>: Linear to the elements between pos and the
Chris@16 1601 //! last element (if pos is near the end) or the first element
Chris@16 1602 //! if(pos is near the beginning).
Chris@16 1603 //! Constant if pos is the first or the last element.
Chris@101 1604 iterator erase(const_iterator pos) BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 1605 {
Chris@16 1606 iterator next = pos.unconst();
Chris@16 1607 ++next;
Chris@16 1608 size_type index = pos - this->members_.m_start;
Chris@16 1609 if (index < (this->size()/2)) {
Chris@101 1610 boost::container::move_backward(this->begin(), pos.unconst(), next);
Chris@16 1611 pop_front();
Chris@16 1612 }
Chris@16 1613 else {
Chris@101 1614 boost::container::move(next, this->end(), pos.unconst());
Chris@16 1615 pop_back();
Chris@16 1616 }
Chris@16 1617 return this->members_.m_start + index;
Chris@16 1618 }
Chris@16 1619
Chris@16 1620 //! <b>Effects</b>: Erases the elements pointed by [first, last).
Chris@16 1621 //!
Chris@16 1622 //! <b>Throws</b>: Nothing.
Chris@16 1623 //!
Chris@16 1624 //! <b>Complexity</b>: Linear to the distance between first and
Chris@16 1625 //! last plus the elements between pos and the
Chris@16 1626 //! last element (if pos is near the end) or the first element
Chris@16 1627 //! if(pos is near the beginning).
Chris@101 1628 iterator erase(const_iterator first, const_iterator last) BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 1629 {
Chris@16 1630 if (first == this->members_.m_start && last == this->members_.m_finish) {
Chris@16 1631 this->clear();
Chris@16 1632 return this->members_.m_finish;
Chris@16 1633 }
Chris@16 1634 else {
Chris@16 1635 const size_type n = static_cast<size_type>(last - first);
Chris@16 1636 const size_type elems_before = static_cast<size_type>(first - this->members_.m_start);
Chris@16 1637 if (elems_before < (this->size() - n) - elems_before) {
Chris@101 1638 boost::container::move_backward(begin(), first.unconst(), last.unconst());
Chris@16 1639 iterator new_start = this->members_.m_start + n;
Chris@16 1640 if(!Base::traits_t::trivial_dctr_after_move)
Chris@16 1641 this->priv_destroy_range(this->members_.m_start, new_start);
Chris@16 1642 this->priv_destroy_nodes(this->members_.m_start.m_node, new_start.m_node);
Chris@16 1643 this->members_.m_start = new_start;
Chris@16 1644 }
Chris@16 1645 else {
Chris@101 1646 boost::container::move(last.unconst(), end(), first.unconst());
Chris@16 1647 iterator new_finish = this->members_.m_finish - n;
Chris@16 1648 if(!Base::traits_t::trivial_dctr_after_move)
Chris@16 1649 this->priv_destroy_range(new_finish, this->members_.m_finish);
Chris@16 1650 this->priv_destroy_nodes(new_finish.m_node + 1, this->members_.m_finish.m_node + 1);
Chris@16 1651 this->members_.m_finish = new_finish;
Chris@16 1652 }
Chris@16 1653 return this->members_.m_start + elems_before;
Chris@16 1654 }
Chris@16 1655 }
Chris@16 1656
Chris@16 1657 //! <b>Effects</b>: Swaps the contents of *this and x.
Chris@16 1658 //!
Chris@16 1659 //! <b>Throws</b>: Nothing.
Chris@16 1660 //!
Chris@16 1661 //! <b>Complexity</b>: Constant.
Chris@16 1662 void swap(deque &x)
Chris@101 1663 BOOST_NOEXCEPT_IF(allocator_traits_type::propagate_on_container_swap::value
Chris@101 1664 || allocator_traits_type::is_always_equal::value)
Chris@16 1665 {
Chris@16 1666 this->swap_members(x);
Chris@16 1667 container_detail::bool_<allocator_traits_type::propagate_on_container_swap::value> flag;
Chris@16 1668 container_detail::swap_alloc(this->alloc(), x.alloc(), flag);
Chris@16 1669 container_detail::swap_alloc(this->ptr_alloc(), x.ptr_alloc(), flag);
Chris@16 1670 }
Chris@16 1671
Chris@16 1672 //! <b>Effects</b>: Erases all the elements of the deque.
Chris@16 1673 //!
Chris@16 1674 //! <b>Throws</b>: Nothing.
Chris@16 1675 //!
Chris@16 1676 //! <b>Complexity</b>: Linear to the number of elements in the deque.
Chris@101 1677 void clear() BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 1678 {
Chris@16 1679 for (index_pointer node = this->members_.m_start.m_node + 1;
Chris@16 1680 node < this->members_.m_finish.m_node;
Chris@16 1681 ++node) {
Chris@16 1682 this->priv_destroy_range(*node, *node + this->s_buffer_size());
Chris@16 1683 this->priv_deallocate_node(*node);
Chris@16 1684 }
Chris@16 1685
Chris@16 1686 if (this->members_.m_start.m_node != this->members_.m_finish.m_node) {
Chris@16 1687 this->priv_destroy_range(this->members_.m_start.m_cur, this->members_.m_start.m_last);
Chris@16 1688 this->priv_destroy_range(this->members_.m_finish.m_first, this->members_.m_finish.m_cur);
Chris@16 1689 this->priv_deallocate_node(this->members_.m_finish.m_first);
Chris@16 1690 }
Chris@16 1691 else
Chris@16 1692 this->priv_destroy_range(this->members_.m_start.m_cur, this->members_.m_finish.m_cur);
Chris@16 1693
Chris@16 1694 this->members_.m_finish = this->members_.m_start;
Chris@16 1695 }
Chris@16 1696
Chris@101 1697 //! <b>Effects</b>: Returns true if x and y are equal
Chris@101 1698 //!
Chris@101 1699 //! <b>Complexity</b>: Linear to the number of elements in the container.
Chris@101 1700 friend bool operator==(const deque& x, const deque& y)
Chris@101 1701 { return x.size() == y.size() && ::boost::container::algo_equal(x.begin(), x.end(), y.begin()); }
Chris@101 1702
Chris@101 1703 //! <b>Effects</b>: Returns true if x and y are unequal
Chris@101 1704 //!
Chris@101 1705 //! <b>Complexity</b>: Linear to the number of elements in the container.
Chris@101 1706 friend bool operator!=(const deque& x, const deque& y)
Chris@101 1707 { return !(x == y); }
Chris@101 1708
Chris@101 1709 //! <b>Effects</b>: Returns true if x is less than y
Chris@101 1710 //!
Chris@101 1711 //! <b>Complexity</b>: Linear to the number of elements in the container.
Chris@101 1712 friend bool operator<(const deque& x, const deque& y)
Chris@101 1713 { return ::boost::container::algo_lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); }
Chris@101 1714
Chris@101 1715 //! <b>Effects</b>: Returns true if x is greater than y
Chris@101 1716 //!
Chris@101 1717 //! <b>Complexity</b>: Linear to the number of elements in the container.
Chris@101 1718 friend bool operator>(const deque& x, const deque& y)
Chris@101 1719 { return y < x; }
Chris@101 1720
Chris@101 1721 //! <b>Effects</b>: Returns true if x is equal or less than y
Chris@101 1722 //!
Chris@101 1723 //! <b>Complexity</b>: Linear to the number of elements in the container.
Chris@101 1724 friend bool operator<=(const deque& x, const deque& y)
Chris@101 1725 { return !(y < x); }
Chris@101 1726
Chris@101 1727 //! <b>Effects</b>: Returns true if x is equal or greater than y
Chris@101 1728 //!
Chris@101 1729 //! <b>Complexity</b>: Linear to the number of elements in the container.
Chris@101 1730 friend bool operator>=(const deque& x, const deque& y)
Chris@101 1731 { return !(x < y); }
Chris@101 1732
Chris@101 1733 //! <b>Effects</b>: x.swap(y)
Chris@101 1734 //!
Chris@101 1735 //! <b>Complexity</b>: Constant.
Chris@101 1736 friend void swap(deque& x, deque& y)
Chris@101 1737 { x.swap(y); }
Chris@101 1738
Chris@101 1739 #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
Chris@16 1740 private:
Chris@16 1741
Chris@101 1742 size_type priv_index_of(const_iterator p) const
Chris@101 1743 {
Chris@101 1744 BOOST_ASSERT(this->cbegin() <= p);
Chris@101 1745 BOOST_ASSERT(p <= this->cend());
Chris@101 1746 return static_cast<size_type>(p - this->cbegin());
Chris@101 1747 }
Chris@101 1748
Chris@16 1749 void priv_erase_last_n(size_type n)
Chris@16 1750 {
Chris@16 1751 if(n == this->size()) {
Chris@16 1752 this->clear();
Chris@16 1753 }
Chris@16 1754 else {
Chris@16 1755 iterator new_finish = this->members_.m_finish - n;
Chris@16 1756 if(!Base::traits_t::trivial_dctr_after_move)
Chris@16 1757 this->priv_destroy_range(new_finish, this->members_.m_finish);
Chris@16 1758 this->priv_destroy_nodes(new_finish.m_node + 1, this->members_.m_finish.m_node + 1);
Chris@16 1759 this->members_.m_finish = new_finish;
Chris@16 1760 }
Chris@16 1761 }
Chris@16 1762
Chris@16 1763 void priv_range_check(size_type n) const
Chris@16 1764 { if (n >= this->size()) throw_out_of_range("deque::at out of range"); }
Chris@16 1765
Chris@16 1766 template <class U>
Chris@101 1767 iterator priv_insert(const_iterator p, BOOST_FWD_REF(U) x)
Chris@16 1768 {
Chris@101 1769 if (p == cbegin()){
Chris@16 1770 this->push_front(::boost::forward<U>(x));
Chris@16 1771 return begin();
Chris@16 1772 }
Chris@101 1773 else if (p == cend()){
Chris@16 1774 this->push_back(::boost::forward<U>(x));
Chris@16 1775 return --end();
Chris@16 1776 }
Chris@16 1777 else {
Chris@16 1778 return priv_insert_aux_impl
Chris@101 1779 ( p, (size_type)1
Chris@101 1780 , container_detail::get_insert_value_proxy<iterator, Allocator>(::boost::forward<U>(x)));
Chris@16 1781 }
Chris@16 1782 }
Chris@16 1783
Chris@16 1784 template <class U>
Chris@16 1785 void priv_push_front(BOOST_FWD_REF(U) x)
Chris@16 1786 {
Chris@16 1787 if(this->priv_push_front_simple_available()){
Chris@16 1788 allocator_traits_type::construct
Chris@16 1789 ( this->alloc(), this->priv_push_front_simple_pos(), ::boost::forward<U>(x));
Chris@16 1790 this->priv_push_front_simple_commit();
Chris@16 1791 }
Chris@16 1792 else{
Chris@16 1793 priv_insert_aux_impl
Chris@101 1794 ( this->cbegin(), (size_type)1
Chris@101 1795 , container_detail::get_insert_value_proxy<iterator, Allocator>(::boost::forward<U>(x)));
Chris@16 1796 }
Chris@16 1797 }
Chris@16 1798
Chris@16 1799 template <class U>
Chris@16 1800 void priv_push_back(BOOST_FWD_REF(U) x)
Chris@16 1801 {
Chris@16 1802 if(this->priv_push_back_simple_available()){
Chris@16 1803 allocator_traits_type::construct
Chris@16 1804 ( this->alloc(), this->priv_push_back_simple_pos(), ::boost::forward<U>(x));
Chris@16 1805 this->priv_push_back_simple_commit();
Chris@16 1806 }
Chris@16 1807 else{
Chris@16 1808 priv_insert_aux_impl
Chris@101 1809 ( this->cend(), (size_type)1
Chris@101 1810 , container_detail::get_insert_value_proxy<iterator, Allocator>(::boost::forward<U>(x)));
Chris@16 1811 }
Chris@16 1812 }
Chris@16 1813
Chris@16 1814 bool priv_push_back_simple_available() const
Chris@16 1815 {
Chris@16 1816 return this->members_.m_map &&
Chris@16 1817 (this->members_.m_finish.m_cur != (this->members_.m_finish.m_last - 1));
Chris@16 1818 }
Chris@16 1819
Chris@16 1820 T *priv_push_back_simple_pos() const
Chris@16 1821 {
Chris@16 1822 return container_detail::to_raw_pointer(this->members_.m_finish.m_cur);
Chris@16 1823 }
Chris@16 1824
Chris@16 1825 void priv_push_back_simple_commit()
Chris@16 1826 {
Chris@16 1827 ++this->members_.m_finish.m_cur;
Chris@16 1828 }
Chris@16 1829
Chris@16 1830 bool priv_push_front_simple_available() const
Chris@16 1831 {
Chris@16 1832 return this->members_.m_map &&
Chris@16 1833 (this->members_.m_start.m_cur != this->members_.m_start.m_first);
Chris@16 1834 }
Chris@16 1835
Chris@16 1836 T *priv_push_front_simple_pos() const
Chris@16 1837 { return container_detail::to_raw_pointer(this->members_.m_start.m_cur) - 1; }
Chris@16 1838
Chris@16 1839 void priv_push_front_simple_commit()
Chris@16 1840 { --this->members_.m_start.m_cur; }
Chris@16 1841
Chris@16 1842 void priv_destroy_range(iterator p, iterator p2)
Chris@16 1843 {
Chris@101 1844 if(!Base::traits_t::trivial_dctr){
Chris@101 1845 for(;p != p2; ++p){
Chris@101 1846 allocator_traits_type::destroy(this->alloc(), container_detail::iterator_to_raw_pointer(p));
Chris@101 1847 }
Chris@16 1848 }
Chris@16 1849 }
Chris@16 1850
Chris@16 1851 void priv_destroy_range(pointer p, pointer p2)
Chris@16 1852 {
Chris@101 1853 if(!Base::traits_t::trivial_dctr){
Chris@101 1854 for(;p != p2; ++p){
Chris@101 1855 allocator_traits_type::destroy(this->alloc(), container_detail::iterator_to_raw_pointer(p));
Chris@101 1856 }
Chris@16 1857 }
Chris@16 1858 }
Chris@16 1859
Chris@16 1860 template<class InsertProxy>
Chris@101 1861 iterator priv_insert_aux_impl(const_iterator p, size_type n, InsertProxy proxy)
Chris@16 1862 {
Chris@16 1863 iterator pos(p.unconst());
Chris@16 1864 const size_type pos_n = p - this->cbegin();
Chris@16 1865 if(!this->members_.m_map){
Chris@16 1866 this->priv_initialize_map(0);
Chris@16 1867 pos = this->begin();
Chris@16 1868 }
Chris@16 1869
Chris@16 1870 const size_type elemsbefore = static_cast<size_type>(pos - this->members_.m_start);
Chris@16 1871 const size_type length = this->size();
Chris@16 1872 if (elemsbefore < length / 2) {
Chris@16 1873 const iterator new_start = this->priv_reserve_elements_at_front(n);
Chris@16 1874 const iterator old_start = this->members_.m_start;
Chris@16 1875 if(!elemsbefore){
Chris@101 1876 proxy.uninitialized_copy_n_and_update(this->alloc(), new_start, n);
Chris@16 1877 this->members_.m_start = new_start;
Chris@16 1878 }
Chris@16 1879 else{
Chris@16 1880 pos = this->members_.m_start + elemsbefore;
Chris@16 1881 if (elemsbefore >= n) {
Chris@16 1882 const iterator start_n = this->members_.m_start + n;
Chris@16 1883 ::boost::container::uninitialized_move_alloc
Chris@16 1884 (this->alloc(), this->members_.m_start, start_n, new_start);
Chris@16 1885 this->members_.m_start = new_start;
Chris@101 1886 boost::container::move(start_n, pos, old_start);
Chris@101 1887 proxy.copy_n_and_update(this->alloc(), pos - n, n);
Chris@16 1888 }
Chris@16 1889 else {
Chris@16 1890 const size_type mid_count = n - elemsbefore;
Chris@16 1891 const iterator mid_start = old_start - mid_count;
Chris@101 1892 proxy.uninitialized_copy_n_and_update(this->alloc(), mid_start, mid_count);
Chris@16 1893 this->members_.m_start = mid_start;
Chris@16 1894 ::boost::container::uninitialized_move_alloc
Chris@16 1895 (this->alloc(), old_start, pos, new_start);
Chris@16 1896 this->members_.m_start = new_start;
Chris@101 1897 proxy.copy_n_and_update(this->alloc(), old_start, elemsbefore);
Chris@16 1898 }
Chris@16 1899 }
Chris@16 1900 }
Chris@16 1901 else {
Chris@16 1902 const iterator new_finish = this->priv_reserve_elements_at_back(n);
Chris@16 1903 const iterator old_finish = this->members_.m_finish;
Chris@16 1904 const size_type elemsafter = length - elemsbefore;
Chris@16 1905 if(!elemsafter){
Chris@101 1906 proxy.uninitialized_copy_n_and_update(this->alloc(), old_finish, n);
Chris@16 1907 this->members_.m_finish = new_finish;
Chris@16 1908 }
Chris@16 1909 else{
Chris@16 1910 pos = old_finish - elemsafter;
Chris@16 1911 if (elemsafter >= n) {
Chris@16 1912 iterator finish_n = old_finish - difference_type(n);
Chris@16 1913 ::boost::container::uninitialized_move_alloc
Chris@16 1914 (this->alloc(), finish_n, old_finish, old_finish);
Chris@16 1915 this->members_.m_finish = new_finish;
Chris@101 1916 boost::container::move_backward(pos, finish_n, old_finish);
Chris@101 1917 proxy.copy_n_and_update(this->alloc(), pos, n);
Chris@16 1918 }
Chris@16 1919 else {
Chris@16 1920 const size_type raw_gap = n - elemsafter;
Chris@16 1921 ::boost::container::uninitialized_move_alloc
Chris@16 1922 (this->alloc(), pos, old_finish, old_finish + raw_gap);
Chris@16 1923 BOOST_TRY{
Chris@101 1924 proxy.copy_n_and_update(this->alloc(), pos, elemsafter);
Chris@101 1925 proxy.uninitialized_copy_n_and_update(this->alloc(), old_finish, raw_gap);
Chris@16 1926 }
Chris@16 1927 BOOST_CATCH(...){
Chris@16 1928 this->priv_destroy_range(old_finish, old_finish + elemsafter);
Chris@16 1929 BOOST_RETHROW
Chris@16 1930 }
Chris@16 1931 BOOST_CATCH_END
Chris@16 1932 this->members_.m_finish = new_finish;
Chris@16 1933 }
Chris@16 1934 }
Chris@16 1935 }
Chris@16 1936 return this->begin() + pos_n;
Chris@16 1937 }
Chris@16 1938
Chris@16 1939 template <class InsertProxy>
Chris@101 1940 iterator priv_insert_back_aux_impl(size_type n, InsertProxy proxy)
Chris@16 1941 {
Chris@16 1942 if(!this->members_.m_map){
Chris@16 1943 this->priv_initialize_map(0);
Chris@16 1944 }
Chris@16 1945
Chris@16 1946 iterator new_finish = this->priv_reserve_elements_at_back(n);
Chris@16 1947 iterator old_finish = this->members_.m_finish;
Chris@101 1948 proxy.uninitialized_copy_n_and_update(this->alloc(), old_finish, n);
Chris@16 1949 this->members_.m_finish = new_finish;
Chris@16 1950 return iterator(this->members_.m_finish - n);
Chris@16 1951 }
Chris@16 1952
Chris@16 1953 template <class InsertProxy>
Chris@101 1954 iterator priv_insert_front_aux_impl(size_type n, InsertProxy proxy)
Chris@16 1955 {
Chris@16 1956 if(!this->members_.m_map){
Chris@16 1957 this->priv_initialize_map(0);
Chris@16 1958 }
Chris@16 1959
Chris@16 1960 iterator new_start = this->priv_reserve_elements_at_front(n);
Chris@101 1961 proxy.uninitialized_copy_n_and_update(this->alloc(), new_start, n);
Chris@16 1962 this->members_.m_start = new_start;
Chris@16 1963 return new_start;
Chris@16 1964 }
Chris@16 1965
Chris@16 1966 iterator priv_fill_insert(const_iterator pos, size_type n, const value_type& x)
Chris@16 1967 {
Chris@16 1968 typedef constant_iterator<value_type, difference_type> c_it;
Chris@16 1969 return this->insert(pos, c_it(x, n), c_it());
Chris@16 1970 }
Chris@16 1971
Chris@16 1972 // Precondition: this->members_.m_start and this->members_.m_finish have already been initialized,
Chris@16 1973 // but none of the deque's elements have yet been constructed.
Chris@16 1974 void priv_fill_initialize(const value_type& value)
Chris@16 1975 {
Chris@101 1976 index_pointer cur = this->members_.m_start.m_node;
Chris@16 1977 BOOST_TRY {
Chris@101 1978 for ( ; cur < this->members_.m_finish.m_node; ++cur){
Chris@16 1979 boost::container::uninitialized_fill_alloc
Chris@16 1980 (this->alloc(), *cur, *cur + this->s_buffer_size(), value);
Chris@16 1981 }
Chris@16 1982 boost::container::uninitialized_fill_alloc
Chris@16 1983 (this->alloc(), this->members_.m_finish.m_first, this->members_.m_finish.m_cur, value);
Chris@16 1984 }
Chris@16 1985 BOOST_CATCH(...){
Chris@16 1986 this->priv_destroy_range(this->members_.m_start, iterator(*cur, cur));
Chris@16 1987 BOOST_RETHROW
Chris@16 1988 }
Chris@16 1989 BOOST_CATCH_END
Chris@16 1990 }
Chris@16 1991
Chris@16 1992 template <class InIt>
Chris@101 1993 typename iterator_enable_if_tag<InIt, std::input_iterator_tag>::type
Chris@101 1994 priv_range_initialize(InIt first, InIt last)
Chris@16 1995 {
Chris@16 1996 this->priv_initialize_map(0);
Chris@16 1997 BOOST_TRY {
Chris@16 1998 for ( ; first != last; ++first)
Chris@16 1999 this->emplace_back(*first);
Chris@16 2000 }
Chris@16 2001 BOOST_CATCH(...){
Chris@16 2002 this->clear();
Chris@16 2003 BOOST_RETHROW
Chris@16 2004 }
Chris@16 2005 BOOST_CATCH_END
Chris@16 2006 }
Chris@16 2007
Chris@16 2008 template <class FwdIt>
Chris@101 2009 typename iterator_disable_if_tag<FwdIt, std::input_iterator_tag>::type
Chris@101 2010 priv_range_initialize(FwdIt first, FwdIt last)
Chris@16 2011 {
Chris@16 2012 size_type n = 0;
Chris@101 2013 n = boost::container::iterator_distance(first, last);
Chris@16 2014 this->priv_initialize_map(n);
Chris@16 2015
Chris@101 2016 index_pointer cur_node = this->members_.m_start.m_node;
Chris@16 2017 BOOST_TRY {
Chris@101 2018 for (; cur_node < this->members_.m_finish.m_node; ++cur_node) {
Chris@16 2019 FwdIt mid = first;
Chris@101 2020 boost::container::iterator_advance(mid, this->s_buffer_size());
Chris@16 2021 ::boost::container::uninitialized_copy_alloc(this->alloc(), first, mid, *cur_node);
Chris@16 2022 first = mid;
Chris@16 2023 }
Chris@16 2024 ::boost::container::uninitialized_copy_alloc(this->alloc(), first, last, this->members_.m_finish.m_first);
Chris@16 2025 }
Chris@16 2026 BOOST_CATCH(...){
Chris@16 2027 this->priv_destroy_range(this->members_.m_start, iterator(*cur_node, cur_node));
Chris@16 2028 BOOST_RETHROW
Chris@16 2029 }
Chris@16 2030 BOOST_CATCH_END
Chris@16 2031 }
Chris@16 2032
Chris@16 2033 // Called only if this->members_.m_finish.m_cur == this->members_.m_finish.m_first.
Chris@101 2034 void priv_pop_back_aux() BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 2035 {
Chris@16 2036 this->priv_deallocate_node(this->members_.m_finish.m_first);
Chris@16 2037 this->members_.m_finish.priv_set_node(this->members_.m_finish.m_node - 1);
Chris@16 2038 this->members_.m_finish.m_cur = this->members_.m_finish.m_last - 1;
Chris@16 2039 allocator_traits_type::destroy
Chris@16 2040 ( this->alloc()
Chris@16 2041 , container_detail::to_raw_pointer(this->members_.m_finish.m_cur)
Chris@16 2042 );
Chris@16 2043 }
Chris@16 2044
Chris@16 2045 // Called only if this->members_.m_start.m_cur == this->members_.m_start.m_last - 1. Note that
Chris@16 2046 // if the deque has at least one element (a precondition for this member
Chris@16 2047 // function), and if this->members_.m_start.m_cur == this->members_.m_start.m_last, then the deque
Chris@16 2048 // must have at least two nodes.
Chris@101 2049 void priv_pop_front_aux() BOOST_NOEXCEPT_OR_NOTHROW
Chris@16 2050 {
Chris@16 2051 allocator_traits_type::destroy
Chris@16 2052 ( this->alloc()
Chris@16 2053 , container_detail::to_raw_pointer(this->members_.m_start.m_cur)
Chris@16 2054 );
Chris@16 2055 this->priv_deallocate_node(this->members_.m_start.m_first);
Chris@16 2056 this->members_.m_start.priv_set_node(this->members_.m_start.m_node + 1);
Chris@16 2057 this->members_.m_start.m_cur = this->members_.m_start.m_first;
Chris@101 2058 }
Chris@16 2059
Chris@16 2060 iterator priv_reserve_elements_at_front(size_type n)
Chris@16 2061 {
Chris@16 2062 size_type vacancies = this->members_.m_start.m_cur - this->members_.m_start.m_first;
Chris@16 2063 if (n > vacancies){
Chris@16 2064 size_type new_elems = n-vacancies;
Chris@16 2065 size_type new_nodes = (new_elems + this->s_buffer_size() - 1) /
Chris@16 2066 this->s_buffer_size();
Chris@16 2067 size_type s = (size_type)(this->members_.m_start.m_node - this->members_.m_map);
Chris@16 2068 if (new_nodes > s){
Chris@16 2069 this->priv_reallocate_map(new_nodes, true);
Chris@16 2070 }
Chris@16 2071 size_type i = 1;
Chris@16 2072 BOOST_TRY {
Chris@16 2073 for (; i <= new_nodes; ++i)
Chris@16 2074 *(this->members_.m_start.m_node - i) = this->priv_allocate_node();
Chris@16 2075 }
Chris@16 2076 BOOST_CATCH(...) {
Chris@16 2077 for (size_type j = 1; j < i; ++j)
Chris@101 2078 this->priv_deallocate_node(*(this->members_.m_start.m_node - j));
Chris@16 2079 BOOST_RETHROW
Chris@16 2080 }
Chris@16 2081 BOOST_CATCH_END
Chris@16 2082 }
Chris@16 2083 return this->members_.m_start - difference_type(n);
Chris@16 2084 }
Chris@16 2085
Chris@16 2086 iterator priv_reserve_elements_at_back(size_type n)
Chris@16 2087 {
Chris@16 2088 size_type vacancies = (this->members_.m_finish.m_last - this->members_.m_finish.m_cur) - 1;
Chris@16 2089 if (n > vacancies){
Chris@16 2090 size_type new_elems = n - vacancies;
Chris@16 2091 size_type new_nodes = (new_elems + this->s_buffer_size() - 1)/s_buffer_size();
Chris@16 2092 size_type s = (size_type)(this->members_.m_map_size - (this->members_.m_finish.m_node - this->members_.m_map));
Chris@16 2093 if (new_nodes + 1 > s){
Chris@16 2094 this->priv_reallocate_map(new_nodes, false);
Chris@16 2095 }
Chris@101 2096 size_type i = 1;
Chris@16 2097 BOOST_TRY {
Chris@101 2098 for (; i <= new_nodes; ++i)
Chris@16 2099 *(this->members_.m_finish.m_node + i) = this->priv_allocate_node();
Chris@16 2100 }
Chris@16 2101 BOOST_CATCH(...) {
Chris@16 2102 for (size_type j = 1; j < i; ++j)
Chris@101 2103 this->priv_deallocate_node(*(this->members_.m_finish.m_node + j));
Chris@16 2104 BOOST_RETHROW
Chris@16 2105 }
Chris@16 2106 BOOST_CATCH_END
Chris@16 2107 }
Chris@16 2108 return this->members_.m_finish + difference_type(n);
Chris@16 2109 }
Chris@16 2110
Chris@16 2111 void priv_reallocate_map(size_type nodes_to_add, bool add_at_front)
Chris@16 2112 {
Chris@16 2113 size_type old_num_nodes = this->members_.m_finish.m_node - this->members_.m_start.m_node + 1;
Chris@16 2114 size_type new_num_nodes = old_num_nodes + nodes_to_add;
Chris@16 2115
Chris@16 2116 index_pointer new_nstart;
Chris@16 2117 if (this->members_.m_map_size > 2 * new_num_nodes) {
Chris@16 2118 new_nstart = this->members_.m_map + (this->members_.m_map_size - new_num_nodes) / 2
Chris@16 2119 + (add_at_front ? nodes_to_add : 0);
Chris@16 2120 if (new_nstart < this->members_.m_start.m_node)
Chris@101 2121 boost::container::move(this->members_.m_start.m_node, this->members_.m_finish.m_node + 1, new_nstart);
Chris@16 2122 else
Chris@101 2123 boost::container::move_backward
Chris@16 2124 (this->members_.m_start.m_node, this->members_.m_finish.m_node + 1, new_nstart + old_num_nodes);
Chris@16 2125 }
Chris@16 2126 else {
Chris@16 2127 size_type new_map_size =
Chris@16 2128 this->members_.m_map_size + container_detail::max_value(this->members_.m_map_size, nodes_to_add) + 2;
Chris@16 2129
Chris@16 2130 index_pointer new_map = this->priv_allocate_map(new_map_size);
Chris@16 2131 new_nstart = new_map + (new_map_size - new_num_nodes) / 2
Chris@16 2132 + (add_at_front ? nodes_to_add : 0);
Chris@101 2133 boost::container::move(this->members_.m_start.m_node, this->members_.m_finish.m_node + 1, new_nstart);
Chris@16 2134 this->priv_deallocate_map(this->members_.m_map, this->members_.m_map_size);
Chris@16 2135
Chris@16 2136 this->members_.m_map = new_map;
Chris@16 2137 this->members_.m_map_size = new_map_size;
Chris@16 2138 }
Chris@16 2139
Chris@16 2140 this->members_.m_start.priv_set_node(new_nstart);
Chris@16 2141 this->members_.m_finish.priv_set_node(new_nstart + old_num_nodes - 1);
Chris@16 2142 }
Chris@101 2143 #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
Chris@16 2144 };
Chris@16 2145
Chris@16 2146 }}
Chris@16 2147
Chris@101 2148 #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
Chris@16 2149
Chris@16 2150 namespace boost {
Chris@16 2151
Chris@16 2152 //!has_trivial_destructor_after_move<> == true_type
Chris@16 2153 //!specialization for optimizations
Chris@16 2154 template <class T, class Allocator>
Chris@16 2155 struct has_trivial_destructor_after_move<boost::container::deque<T, Allocator> >
Chris@101 2156 {
Chris@101 2157 typedef typename ::boost::container::allocator_traits<Allocator>::pointer pointer;
Chris@101 2158 static const bool value = ::boost::has_trivial_destructor_after_move<Allocator>::value &&
Chris@101 2159 ::boost::has_trivial_destructor_after_move<pointer>::value;
Chris@101 2160 };
Chris@16 2161
Chris@16 2162 }
Chris@16 2163
Chris@101 2164 #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
Chris@16 2165
Chris@16 2166 #include <boost/container/detail/config_end.hpp>
Chris@16 2167
Chris@16 2168 #endif // #ifndef BOOST_CONTAINER_DEQUE_HPP