summaryrefslogtreecommitdiff
path: root/boost/container/deque.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/container/deque.hpp')
-rw-r--r--boost/container/deque.hpp2244
1 files changed, 1131 insertions, 1113 deletions
diff --git a/boost/container/deque.hpp b/boost/container/deque.hpp
index 6a85ae9486..d8a546c86f 100644
--- a/boost/container/deque.hpp
+++ b/boost/container/deque.hpp
@@ -1,39 +1,17 @@
//////////////////////////////////////////////////////////////////////////////
//
-// (C) Copyright Ion Gaztanaga 2005-2012. Distributed under the Boost
+// (C) Copyright Ion Gaztanaga 2005-2013. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/container for documentation.
//
//////////////////////////////////////////////////////////////////////////////
-// Copyright (c) 1996,1997
-// Silicon Graphics Computer Systems, Inc.
-//
-// Permission to use, copy, modify, distribute and sell this software
-// and its documentation for any purpose is hereby granted without fee,
-// provided that the above copyright notice appear in all copies and
-// that both that copyright notice and this permission notice appear
-// in supporting documentation. Silicon Graphics makes no
-// representations about the suitability of this software for any
-// purpose. It is provided "as is" without express or implied warranty.
-//
-//
-// Copyright (c) 1994
-// Hewlett-Packard Company
-//
-// Permission to use, copy, modify, distribute and sell this software
-// and its documentation for any purpose is hereby granted without fee,
-// provided that the above copyright notice appear in all copies and
-// that both that copyright notice and this permission notice appear
-// in supporting documentation. Hewlett-Packard Company makes no
-// representations about the suitability of this software for any
-// purpose. It is provided "as is" without express or implied warranty.
#ifndef BOOST_CONTAINER_DEQUE_HPP
#define BOOST_CONTAINER_DEQUE_HPP
-#if (defined _MSC_VER) && (_MSC_VER >= 1200)
+#if defined(_MSC_VER)
# pragma once
#endif
@@ -46,41 +24,43 @@
#include <boost/container/detail/mpl.hpp>
#include <boost/container/allocator_traits.hpp>
#include <boost/container/container_fwd.hpp>
+#include <boost/container/throw_exception.hpp>
#include <cstddef>
#include <iterator>
#include <boost/assert.hpp>
#include <memory>
#include <algorithm>
-#include <stdexcept>
-#include <boost/detail/no_exceptions_support.hpp>
+#include <boost/core/no_exceptions_support.hpp>
#include <boost/type_traits/has_trivial_destructor.hpp>
#include <boost/type_traits/has_trivial_copy.hpp>
#include <boost/type_traits/has_trivial_assign.hpp>
#include <boost/type_traits/has_nothrow_copy.hpp>
#include <boost/type_traits/has_nothrow_assign.hpp>
-#include <boost/move/move.hpp>
-#include <boost/move/move_helpers.hpp>
+#include <boost/move/utility_core.hpp>
+#include <boost/move/iterator.hpp>
+#include <boost/move/algorithm.hpp>
+#include <boost/move/detail/move_helpers.hpp>
+#include <boost/move/traits.hpp>
#include <boost/container/detail/advanced_insert_int.hpp>
+#include <boost/core/no_exceptions_support.hpp>
+
+#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
+#include <initializer_list>
+#endif
namespace boost {
namespace container {
-/// @cond
-#ifdef BOOST_CONTAINER_DOXYGEN_INVOKED
-template <class T, class A = std::allocator<T> >
-#else
-template <class T, class A>
-#endif
+#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
+template <class T, class Allocator>
class deque;
-template <class T, class A>
+template <class T>
struct deque_value_traits
{
typedef T value_type;
- typedef A allocator_type;
static const bool trivial_dctr = boost::has_trivial_destructor<value_type>::value;
- static const bool trivial_dctr_after_move = false;
- //::boost::has_trivial_destructor_after_move<value_type>::value || trivial_dctr;
+ static const bool trivial_dctr_after_move = ::boost::has_trivial_destructor_after_move<value_type>::value;
static const bool trivial_copy = has_trivial_copy<value_type>::value;
static const bool nothrow_copy = has_nothrow_copy<value_type>::value;
static const bool trivial_assign = has_trivial_assign<value_type>::value;
@@ -90,290 +70,257 @@ struct deque_value_traits
// Note: this function is simply a kludge to work around several compilers'
// bugs in handling constant expressions.
-inline std::size_t deque_buf_size(std::size_t size)
- { return size < 512 ? std::size_t(512 / size) : std::size_t(1); }
+template<class T>
+struct deque_buf_size
+{
+ static const std::size_t min_size = 512u;
+ static const std::size_t sizeof_t = sizeof(T);
+ static const std::size_t value = sizeof_t < min_size ? (min_size/sizeof_t) : std::size_t(1);
+};
-// Deque base class. It has two purposes. First, its constructor
-// and destructor allocate (but don't initialize) storage. This makes
-// exception safety easier.
-template <class T, class A>
-class deque_base
+namespace container_detail {
+
+// Class invariants:
+// For any nonsingular iterator i:
+// i.node is the address of an element in the map array. The
+// contents of i.node is a pointer to the beginning of a node.
+// i.first == //(i.node)
+// i.last == i.first + node_size
+// i.cur is a pointer in the range [i.first, i.last). NOTE:
+// the implication of this is that i.cur is always a dereferenceable
+// pointer, even if i is a past-the-end iterator.
+// Start and Finish are always nonsingular iterators. NOTE: this means
+// that an empty deque must have one node, and that a deque
+// with N elements, where N is the buffer size, must have two nodes.
+// For every node other than start.node and finish.node, every element
+// in the node is an initialized object. If start.node == finish.node,
+// then [start.cur, finish.cur) are initialized objects, and
+// the elements outside that range are uninitialized storage. Otherwise,
+// [start.cur, start.last) and [finish.first, finish.cur) are initialized
+// objects, and [start.first, start.cur) and [finish.cur, finish.last)
+// are uninitialized storage.
+// [map, map + map_size) is a valid, non-empty range.
+// [start.node, finish.node] is a valid range contained within
+// [map, map + map_size).
+// Allocator pointer in the range [map, map + map_size) points to an allocated node
+// if and only if the pointer is in the range [start.node, finish.node].
+template<class Pointer, bool IsConst>
+class deque_iterator
{
- BOOST_COPYABLE_AND_MOVABLE(deque_base)
public:
- typedef allocator_traits<A> val_alloc_traits_type;
- typedef typename val_alloc_traits_type::value_type val_alloc_val;
- typedef typename val_alloc_traits_type::pointer val_alloc_ptr;
- typedef typename val_alloc_traits_type::const_pointer val_alloc_cptr;
- typedef typename val_alloc_traits_type::reference val_alloc_ref;
- typedef typename val_alloc_traits_type::const_reference val_alloc_cref;
- typedef typename val_alloc_traits_type::difference_type val_alloc_diff;
- typedef typename val_alloc_traits_type::size_type val_alloc_size;
- typedef typename val_alloc_traits_type::template
- portable_rebind_alloc<val_alloc_ptr>::type ptr_alloc_t;
- typedef allocator_traits<ptr_alloc_t> ptr_alloc_traits_type;
- typedef typename ptr_alloc_traits_type::value_type ptr_alloc_val;
- typedef typename ptr_alloc_traits_type::pointer ptr_alloc_ptr;
- typedef typename ptr_alloc_traits_type::const_pointer ptr_alloc_cptr;
- typedef typename ptr_alloc_traits_type::reference ptr_alloc_ref;
- typedef typename ptr_alloc_traits_type::const_reference ptr_alloc_cref;
- typedef A allocator_type;
- typedef allocator_type stored_allocator_type;
- typedef val_alloc_size size_type;
+ typedef std::random_access_iterator_tag iterator_category;
+ typedef typename boost::intrusive::pointer_traits<Pointer>::element_type value_type;
+ typedef typename boost::intrusive::pointer_traits<Pointer>::difference_type difference_type;
+ typedef typename if_c
+ < IsConst
+ , typename boost::intrusive::pointer_traits<Pointer>::template
+ rebind_pointer<const value_type>::type
+ , Pointer
+ >::type pointer;
+ typedef typename if_c
+ < IsConst
+ , const value_type&
+ , value_type&
+ >::type reference;
+
+ static std::size_t s_buffer_size()
+ { return deque_buf_size<value_type>::value; }
+
+ typedef Pointer val_alloc_ptr;
+ typedef typename boost::intrusive::pointer_traits<Pointer>::
+ template rebind_pointer<Pointer>::type index_pointer;
+
+ Pointer m_cur;
+ Pointer m_first;
+ Pointer m_last;
+ index_pointer m_node;
- protected:
+ public:
- typedef deque_value_traits<T, A> traits_t;
- typedef ptr_alloc_t map_allocator_type;
+ Pointer get_cur() const { return m_cur; }
+ Pointer get_first() const { return m_first; }
+ Pointer get_last() const { return m_last; }
+ index_pointer get_node() const { return m_node; }
- static size_type s_buffer_size() { return deque_buf_size(sizeof(T)); }
+ deque_iterator(val_alloc_ptr x, index_pointer y) BOOST_CONTAINER_NOEXCEPT
+ : m_cur(x), m_first(*y), m_last(*y + s_buffer_size()), m_node(y)
+ {}
- val_alloc_ptr priv_allocate_node()
- { return this->alloc().allocate(s_buffer_size()); }
+ deque_iterator() BOOST_CONTAINER_NOEXCEPT
+ : m_cur(), m_first(), m_last(), m_node() //Value initialization to achieve "null iterators" (N3644)
+ {}
- void priv_deallocate_node(val_alloc_ptr p)
- { this->alloc().deallocate(p, s_buffer_size()); }
+ deque_iterator(deque_iterator<Pointer, false> const& x) BOOST_CONTAINER_NOEXCEPT
+ : m_cur(x.get_cur()), m_first(x.get_first()), m_last(x.get_last()), m_node(x.get_node())
+ {}
- ptr_alloc_ptr priv_allocate_map(size_type n)
- { return this->ptr_alloc().allocate(n); }
+ deque_iterator(Pointer cur, Pointer first, Pointer last, index_pointer node) BOOST_CONTAINER_NOEXCEPT
+ : m_cur(cur), m_first(first), m_last(last), m_node(node)
+ {}
- void priv_deallocate_map(ptr_alloc_ptr p, size_type n)
- { this->ptr_alloc().deallocate(p, n); }
+ deque_iterator<Pointer, false> unconst() const BOOST_CONTAINER_NOEXCEPT
+ {
+ return deque_iterator<Pointer, false>(this->get_cur(), this->get_first(), this->get_last(), this->get_node());
+ }
- public:
- // Class invariants:
- // For any nonsingular iterator i:
- // i.node is the address of an element in the map array. The
- // contents of i.node is a pointer to the beginning of a node.
- // i.first == //(i.node)
- // i.last == i.first + node_size
- // i.cur is a pointer in the range [i.first, i.last). NOTE:
- // the implication of this is that i.cur is always a dereferenceable
- // pointer, even if i is a past-the-end iterator.
- // Start and Finish are always nonsingular iterators. NOTE: this means
- // that an empty deque must have one node, and that a deque
- // with N elements, where N is the buffer size, must have two nodes.
- // For every node other than start.node and finish.node, every element
- // in the node is an initialized object. If start.node == finish.node,
- // then [start.cur, finish.cur) are initialized objects, and
- // the elements outside that range are uninitialized storage. Otherwise,
- // [start.cur, start.last) and [finish.first, finish.cur) are initialized
- // objects, and [start.first, start.cur) and [finish.cur, finish.last)
- // are uninitialized storage.
- // [map, map + map_size) is a valid, non-empty range.
- // [start.node, finish.node] is a valid range contained within
- // [map, map + map_size).
- // A pointer in the range [map, map + map_size) points to an allocated node
- // if and only if the pointer is in the range [start.node, finish.node].
- class const_iterator
- : public std::iterator<std::random_access_iterator_tag,
- val_alloc_val, val_alloc_diff,
- val_alloc_cptr, val_alloc_cref>
- {
- public:
- static size_type s_buffer_size() { return deque_base<T, A>::s_buffer_size(); }
-
- typedef std::random_access_iterator_tag iterator_category;
- typedef val_alloc_val value_type;
- typedef val_alloc_cptr pointer;
- typedef val_alloc_cref reference;
- typedef val_alloc_diff difference_type;
-
- typedef ptr_alloc_ptr index_pointer;
- typedef const_iterator self_t;
-
- friend class deque<T, A>;
- friend class deque_base<T, A>;
-
- protected:
- val_alloc_ptr m_cur;
- val_alloc_ptr m_first;
- val_alloc_ptr m_last;
- index_pointer m_node;
-
- public:
- const_iterator(val_alloc_ptr x, index_pointer y)
- : m_cur(x), m_first(*y),
- m_last(*y + s_buffer_size()), m_node(y) {}
-
- const_iterator() : m_cur(0), m_first(0), m_last(0), m_node(0) {}
-
- const_iterator(const const_iterator& x)
- : m_cur(x.m_cur), m_first(x.m_first),
- m_last(x.m_last), m_node(x.m_node) {}
-
- reference operator*() const
- { return *this->m_cur; }
-
- pointer operator->() const
- { return this->m_cur; }
-
- difference_type operator-(const self_t& x) const
- {
- if(!this->m_cur && !x.m_cur){
- return 0;
- }
- return difference_type(this->s_buffer_size()) * (this->m_node - x.m_node - 1) +
- (this->m_cur - this->m_first) + (x.m_last - x.m_cur);
- }
+ reference operator*() const BOOST_CONTAINER_NOEXCEPT
+ { return *this->m_cur; }
- self_t& operator++()
- {
- ++this->m_cur;
- if (this->m_cur == this->m_last) {
- this->priv_set_node(this->m_node + 1);
- this->m_cur = this->m_first;
- }
- return *this;
- }
+ pointer operator->() const BOOST_CONTAINER_NOEXCEPT
+ { return this->m_cur; }
- self_t operator++(int)
- {
- self_t tmp = *this;
- ++*this;
- return tmp;
+ difference_type operator-(const deque_iterator& x) const BOOST_CONTAINER_NOEXCEPT
+ {
+ if(!this->m_cur && !x.m_cur){
+ return 0;
}
+ return difference_type(this->s_buffer_size()) * (this->m_node - x.m_node - 1) +
+ (this->m_cur - this->m_first) + (x.m_last - x.m_cur);
+ }
- self_t& operator--()
- {
- if (this->m_cur == this->m_first) {
- this->priv_set_node(this->m_node - 1);
- this->m_cur = this->m_last;
- }
- --this->m_cur;
- return *this;
+ deque_iterator& operator++() BOOST_CONTAINER_NOEXCEPT
+ {
+ ++this->m_cur;
+ if (this->m_cur == this->m_last) {
+ this->priv_set_node(this->m_node + 1);
+ this->m_cur = this->m_first;
}
+ return *this;
+ }
- self_t operator--(int)
- {
- self_t tmp = *this;
- --*this;
- return tmp;
- }
+ deque_iterator operator++(int) BOOST_CONTAINER_NOEXCEPT
+ {
+ deque_iterator tmp(*this);
+ ++*this;
+ return tmp;
+ }
- self_t& operator+=(difference_type n)
- {
- difference_type offset = n + (this->m_cur - this->m_first);
- if (offset >= 0 && offset < difference_type(this->s_buffer_size()))
- this->m_cur += n;
- else {
- difference_type node_offset =
- offset > 0 ? offset / difference_type(this->s_buffer_size())
- : -difference_type((-offset - 1) / this->s_buffer_size()) - 1;
- this->priv_set_node(this->m_node + node_offset);
- this->m_cur = this->m_first +
- (offset - node_offset * difference_type(this->s_buffer_size()));
- }
- return *this;
+ deque_iterator& operator--() BOOST_CONTAINER_NOEXCEPT
+ {
+ if (this->m_cur == this->m_first) {
+ this->priv_set_node(this->m_node - 1);
+ this->m_cur = this->m_last;
}
+ --this->m_cur;
+ return *this;
+ }
- self_t operator+(difference_type n) const
- { self_t tmp = *this; return tmp += n; }
-
- self_t& operator-=(difference_type n)
- { return *this += -n; }
-
- self_t operator-(difference_type n) const
- { self_t tmp = *this; return tmp -= n; }
-
- reference operator[](difference_type n) const
- { return *(*this + n); }
+ deque_iterator operator--(int) BOOST_CONTAINER_NOEXCEPT
+ {
+ deque_iterator tmp(*this);
+ --*this;
+ return tmp;
+ }
- bool operator==(const self_t& x) const
- { return this->m_cur == x.m_cur; }
+ deque_iterator& operator+=(difference_type n) BOOST_CONTAINER_NOEXCEPT
+ {
+ difference_type offset = n + (this->m_cur - this->m_first);
+ if (offset >= 0 && offset < difference_type(this->s_buffer_size()))
+ this->m_cur += n;
+ else {
+ difference_type node_offset =
+ offset > 0 ? offset / difference_type(this->s_buffer_size())
+ : -difference_type((-offset - 1) / this->s_buffer_size()) - 1;
+ this->priv_set_node(this->m_node + node_offset);
+ this->m_cur = this->m_first +
+ (offset - node_offset * difference_type(this->s_buffer_size()));
+ }
+ return *this;
+ }
- bool operator!=(const self_t& x) const
- { return !(*this == x); }
+ deque_iterator operator+(difference_type n) const BOOST_CONTAINER_NOEXCEPT
+ { deque_iterator tmp(*this); return tmp += n; }
- bool operator<(const self_t& x) const
- {
- return (this->m_node == x.m_node) ?
- (this->m_cur < x.m_cur) : (this->m_node < x.m_node);
- }
+ deque_iterator& operator-=(difference_type n) BOOST_CONTAINER_NOEXCEPT
+ { return *this += -n; }
- bool operator>(const self_t& x) const
- { return x < *this; }
+ deque_iterator operator-(difference_type n) const BOOST_CONTAINER_NOEXCEPT
+ { deque_iterator tmp(*this); return tmp -= n; }
- bool operator<=(const self_t& x) const
- { return !(x < *this); }
+ reference operator[](difference_type n) const BOOST_CONTAINER_NOEXCEPT
+ { return *(*this + n); }
- bool operator>=(const self_t& x) const
- { return !(*this < x); }
+ friend bool operator==(const deque_iterator& l, const deque_iterator& r) BOOST_CONTAINER_NOEXCEPT
+ { return l.m_cur == r.m_cur; }
- void priv_set_node(index_pointer new_node)
- {
- this->m_node = new_node;
- this->m_first = *new_node;
- this->m_last = this->m_first + difference_type(this->s_buffer_size());
- }
+ friend bool operator!=(const deque_iterator& l, const deque_iterator& r) BOOST_CONTAINER_NOEXCEPT
+ { return l.m_cur != r.m_cur; }
- friend const_iterator operator+(difference_type n, const const_iterator& x)
- { return x + n; }
- };
+ friend bool operator<(const deque_iterator& l, const deque_iterator& r) BOOST_CONTAINER_NOEXCEPT
+ { return (l.m_node == r.m_node) ? (l.m_cur < r.m_cur) : (l.m_node < r.m_node); }
- //Deque iterator
- class iterator : public const_iterator
- {
- public:
- typedef std::random_access_iterator_tag iterator_category;
- typedef val_alloc_val value_type;
- typedef val_alloc_ptr pointer;
- typedef val_alloc_ref reference;
- typedef val_alloc_diff difference_type;
- typedef ptr_alloc_ptr index_pointer;
- typedef const_iterator self_t;
+ friend bool operator>(const deque_iterator& l, const deque_iterator& r) BOOST_CONTAINER_NOEXCEPT
+ { return r < l; }
- friend class deque<T, A>;
- friend class deque_base<T, A>;
+ friend bool operator<=(const deque_iterator& l, const deque_iterator& r) BOOST_CONTAINER_NOEXCEPT
+ { return !(r < l); }
- private:
- explicit iterator(const const_iterator& x) : const_iterator(x){}
+ friend bool operator>=(const deque_iterator& l, const deque_iterator& r) BOOST_CONTAINER_NOEXCEPT
+ { return !(l < r); }
- public:
- //Constructors
- iterator(val_alloc_ptr x, index_pointer y) : const_iterator(x, y){}
- iterator() : const_iterator(){}
- //iterator(const const_iterator &cit) : const_iterator(cit){}
- iterator(const iterator& x) : const_iterator(x){}
+ void priv_set_node(index_pointer new_node) BOOST_CONTAINER_NOEXCEPT
+ {
+ this->m_node = new_node;
+ this->m_first = *new_node;
+ this->m_last = this->m_first + this->s_buffer_size();
+ }
- //Pointer like operators
- reference operator*() const { return *this->m_cur; }
- pointer operator->() const { return this->m_cur; }
+ friend deque_iterator operator+(difference_type n, deque_iterator x) BOOST_CONTAINER_NOEXCEPT
+ { return x += n; }
+};
- reference operator[](difference_type n) const { return *(*this + n); }
+} //namespace container_detail {
- //Increment / Decrement
- iterator& operator++()
- { this->const_iterator::operator++(); return *this; }
+// Deque base class. It has two purposes. First, its constructor
+// and destructor allocate (but don't initialize) storage. This makes
+// exception safety easier.
+template <class Allocator>
+class deque_base
+{
+ BOOST_COPYABLE_AND_MOVABLE(deque_base)
+ public:
+ typedef allocator_traits<Allocator> val_alloc_traits_type;
+ typedef typename val_alloc_traits_type::value_type val_alloc_val;
+ typedef typename val_alloc_traits_type::pointer val_alloc_ptr;
+ typedef typename val_alloc_traits_type::const_pointer val_alloc_cptr;
+ typedef typename val_alloc_traits_type::reference val_alloc_ref;
+ typedef typename val_alloc_traits_type::const_reference val_alloc_cref;
+ typedef typename val_alloc_traits_type::difference_type val_alloc_diff;
+ typedef typename val_alloc_traits_type::size_type val_alloc_size;
+ typedef typename val_alloc_traits_type::template
+ portable_rebind_alloc<val_alloc_ptr>::type ptr_alloc_t;
+ typedef allocator_traits<ptr_alloc_t> ptr_alloc_traits_type;
+ typedef typename ptr_alloc_traits_type::value_type ptr_alloc_val;
+ typedef typename ptr_alloc_traits_type::pointer ptr_alloc_ptr;
+ typedef typename ptr_alloc_traits_type::const_pointer ptr_alloc_cptr;
+ typedef typename ptr_alloc_traits_type::reference ptr_alloc_ref;
+ typedef typename ptr_alloc_traits_type::const_reference ptr_alloc_cref;
+ typedef Allocator allocator_type;
+ typedef allocator_type stored_allocator_type;
+ typedef val_alloc_size size_type;
- iterator operator++(int)
- { iterator tmp = *this; ++*this; return tmp; }
-
- iterator& operator--()
- { this->const_iterator::operator--(); return *this; }
+ protected:
- iterator operator--(int)
- { iterator tmp = *this; --*this; return tmp; }
+ typedef deque_value_traits<val_alloc_val> traits_t;
+ typedef ptr_alloc_t map_allocator_type;
- // Arithmetic
- iterator& operator+=(difference_type off)
- { this->const_iterator::operator+=(off); return *this; }
+ static size_type s_buffer_size() BOOST_CONTAINER_NOEXCEPT
+ { return deque_buf_size<val_alloc_val>::value; }
- iterator operator+(difference_type off) const
- { return iterator(this->const_iterator::operator+(off)); }
+ val_alloc_ptr priv_allocate_node()
+ { return this->alloc().allocate(s_buffer_size()); }
- friend iterator operator+(difference_type off, const iterator& right)
- { return iterator(off+static_cast<const const_iterator &>(right)); }
+ void priv_deallocate_node(val_alloc_ptr p) BOOST_CONTAINER_NOEXCEPT
+ { this->alloc().deallocate(p, s_buffer_size()); }
- iterator& operator-=(difference_type off)
- { this->const_iterator::operator-=(off); return *this; }
+ ptr_alloc_ptr priv_allocate_map(size_type n)
+ { return this->ptr_alloc().allocate(n); }
- iterator operator-(difference_type off) const
- { return iterator(this->const_iterator::operator-(off)); }
+ void priv_deallocate_map(ptr_alloc_ptr p, size_type n) BOOST_CONTAINER_NOEXCEPT
+ { this->ptr_alloc().deallocate(p, n); }
- difference_type operator-(const const_iterator& right) const
- { return static_cast<const const_iterator&>(*this) - right; }
- };
+ typedef container_detail::deque_iterator<val_alloc_ptr, false> iterator;
+ typedef container_detail::deque_iterator<val_alloc_ptr, true > const_iterator;
deque_base(size_type num_elements, const allocator_type& a)
: members_(a)
@@ -402,10 +349,10 @@ class deque_base
private:
deque_base(const deque_base&);
-
+
protected:
- void swap_members(deque_base &x)
+ void swap_members(deque_base &x) BOOST_CONTAINER_NOEXCEPT
{
std::swap(this->members_.m_start, x.members_.m_start);
std::swap(this->members_.m_finish, x.members_.m_finish);
@@ -423,7 +370,7 @@ class deque_base
ptr_alloc_ptr nstart = this->members_.m_map + (this->members_.m_map_size - num_nodes) / 2;
ptr_alloc_ptr nfinish = nstart + num_nodes;
-
+
BOOST_TRY {
this->priv_create_nodes(nstart, nfinish);
}
@@ -457,13 +404,13 @@ class deque_base
BOOST_CATCH_END
}
- void priv_destroy_nodes(ptr_alloc_ptr nstart, ptr_alloc_ptr nfinish)
+ void priv_destroy_nodes(ptr_alloc_ptr nstart, ptr_alloc_ptr nfinish) BOOST_CONTAINER_NOEXCEPT
{
for (ptr_alloc_ptr n = nstart; n < nfinish; ++n)
this->priv_deallocate_node(*n);
}
- void priv_clear_map()
+ void priv_clear_map() BOOST_CONTAINER_NOEXCEPT
{
if (this->members_.m_map) {
this->priv_destroy_nodes(this->members_.m_start.m_node, this->members_.m_finish.m_node + 1);
@@ -508,324 +455,76 @@ class deque_base
iterator m_finish;
} members_;
- ptr_alloc_t &ptr_alloc()
+ ptr_alloc_t &ptr_alloc() BOOST_CONTAINER_NOEXCEPT
{ return members_; }
-
- const ptr_alloc_t &ptr_alloc() const
+
+ const ptr_alloc_t &ptr_alloc() const BOOST_CONTAINER_NOEXCEPT
{ return members_; }
- allocator_type &alloc()
+ allocator_type &alloc() BOOST_CONTAINER_NOEXCEPT
{ return members_; }
-
- const allocator_type &alloc() const
+
+ const allocator_type &alloc() const BOOST_CONTAINER_NOEXCEPT
{ return members_; }
};
-/// @endcond
+#endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
-//! Deque class
-//!
#ifdef BOOST_CONTAINER_DOXYGEN_INVOKED
-template <class T, class A = std::allocator<T> >
+//! A double-ended queue is a sequence that supports random access to elements, constant time insertion
+//! and removal of elements at the end of the sequence, and linear time insertion and removal of elements in the middle.
+//!
+//! \tparam T The type of object that is stored in the deque
+//! \tparam Allocator The allocator used for all internal memory management
+template <class T, class Allocator = std::allocator<T> >
#else
-template <class T, class A>
+template <class T, class Allocator>
#endif
-class deque : protected deque_base<T, A>
+class deque : protected deque_base<Allocator>
{
- /// @cond
+ #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
private:
- typedef deque_base<T, A> Base;
- typedef typename Base::val_alloc_val val_alloc_val;
- typedef typename Base::val_alloc_ptr val_alloc_ptr;
- typedef typename Base::val_alloc_cptr val_alloc_cptr;
- typedef typename Base::val_alloc_ref val_alloc_ref;
- typedef typename Base::val_alloc_cref val_alloc_cref;
- typedef typename Base::val_alloc_size val_alloc_size;
- typedef typename Base::val_alloc_diff val_alloc_diff;
-
- typedef typename Base::ptr_alloc_t ptr_alloc_t;
- typedef typename Base::ptr_alloc_val ptr_alloc_val;
- typedef typename Base::ptr_alloc_ptr ptr_alloc_ptr;
- typedef typename Base::ptr_alloc_cptr ptr_alloc_cptr;
- typedef typename Base::ptr_alloc_ref ptr_alloc_ref;
- typedef typename Base::ptr_alloc_cref ptr_alloc_cref;
- /// @endcond
-
- public: // Basic types
- typedef T value_type;
- typedef val_alloc_ptr pointer;
- typedef val_alloc_cptr const_pointer;
- typedef val_alloc_ref reference;
- typedef val_alloc_cref const_reference;
- typedef val_alloc_size size_type;
- typedef val_alloc_diff difference_type;
- typedef typename Base::allocator_type allocator_type;
-
- public: // Iterators
- typedef typename Base::iterator iterator;
- typedef typename Base::const_iterator const_iterator;
-
- typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
- typedef std::reverse_iterator<iterator> reverse_iterator;
-
- typedef allocator_type stored_allocator_type;
-
- /// @cond
+ typedef deque_base<Allocator> Base;
+ #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
+
+ public:
+
+ //////////////////////////////////////////////
+ //
+ // types
+ //
+ //////////////////////////////////////////////
+
+ typedef T value_type;
+ typedef typename ::boost::container::allocator_traits<Allocator>::pointer pointer;
+ typedef typename ::boost::container::allocator_traits<Allocator>::const_pointer const_pointer;
+ typedef typename ::boost::container::allocator_traits<Allocator>::reference reference;
+ typedef typename ::boost::container::allocator_traits<Allocator>::const_reference const_reference;
+ typedef typename ::boost::container::allocator_traits<Allocator>::size_type size_type;
+ typedef typename ::boost::container::allocator_traits<Allocator>::difference_type difference_type;
+ typedef Allocator allocator_type;
+ typedef BOOST_CONTAINER_IMPDEF(allocator_type) stored_allocator_type;
+ typedef BOOST_CONTAINER_IMPDEF(typename Base::iterator) iterator;
+ typedef BOOST_CONTAINER_IMPDEF(typename Base::const_iterator) const_iterator;
+ typedef BOOST_CONTAINER_IMPDEF(container_detail::reverse_iterator<iterator>) reverse_iterator;
+ typedef BOOST_CONTAINER_IMPDEF(container_detail::reverse_iterator<const_iterator>) const_reverse_iterator;
+
+ #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
private: // Internal typedefs
BOOST_COPYABLE_AND_MOVABLE(deque)
- typedef ptr_alloc_ptr index_pointer;
+ typedef typename Base::ptr_alloc_ptr index_pointer;
static size_type s_buffer_size()
{ return Base::s_buffer_size(); }
- typedef container_detail::advanced_insert_aux_int<iterator> advanced_insert_aux_int_t;
- typedef repeat_iterator<T, difference_type> r_iterator;
- typedef boost::move_iterator<r_iterator> move_it;
- typedef allocator_traits<A> allocator_traits_type;
+ typedef allocator_traits<Allocator> allocator_traits_type;
- /// @endcond
+ #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
public:
-
- //! <b>Effects</b>: Returns a copy of the internal allocator.
- //!
- //! <b>Throws</b>: If allocator's copy constructor throws.
- //!
- //! <b>Complexity</b>: Constant.
- allocator_type get_allocator() const BOOST_CONTAINER_NOEXCEPT
- { return Base::alloc(); }
-
- //! <b>Effects</b>: Returns a reference to the internal allocator.
- //!
- //! <b>Throws</b>: Nothing
- //!
- //! <b>Complexity</b>: Constant.
- //!
- //! <b>Note</b>: Non-standard extension.
- const stored_allocator_type &get_stored_allocator() const BOOST_CONTAINER_NOEXCEPT
- { return Base::alloc(); }
-
- //! <b>Effects</b>: Returns a reference to the internal allocator.
- //!
- //! <b>Throws</b>: Nothing
- //!
- //! <b>Complexity</b>: Constant.
- //!
- //! <b>Note</b>: Non-standard extension.
- stored_allocator_type &get_stored_allocator() BOOST_CONTAINER_NOEXCEPT
- { return Base::alloc(); }
-
- //! <b>Effects</b>: Returns an iterator to the first element contained in the deque.
- //!
- //! <b>Throws</b>: Nothing.
- //!
- //! <b>Complexity</b>: Constant.
- iterator begin() BOOST_CONTAINER_NOEXCEPT
- { return this->members_.m_start; }
-
- //! <b>Effects</b>: Returns an iterator to the end of the deque.
- //!
- //! <b>Throws</b>: Nothing.
- //!
- //! <b>Complexity</b>: Constant.
- iterator end() BOOST_CONTAINER_NOEXCEPT
- { return this->members_.m_finish; }
-
- //! <b>Effects</b>: Returns a const_iterator to the first element contained in the deque.
- //!
- //! <b>Throws</b>: Nothing.
- //!
- //! <b>Complexity</b>: Constant.
- const_iterator begin() const BOOST_CONTAINER_NOEXCEPT
- { return this->members_.m_start; }
-
- //! <b>Effects</b>: Returns a const_iterator to the end of the deque.
- //!
- //! <b>Throws</b>: Nothing.
- //!
- //! <b>Complexity</b>: Constant.
- const_iterator end() const BOOST_CONTAINER_NOEXCEPT
- { return this->members_.m_finish; }
-
- //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning
- //! of the reversed deque.
- //!
- //! <b>Throws</b>: Nothing.
- //!
- //! <b>Complexity</b>: Constant.
- reverse_iterator rbegin() BOOST_CONTAINER_NOEXCEPT
- { return reverse_iterator(this->members_.m_finish); }
-
- //! <b>Effects</b>: Returns a reverse_iterator pointing to the end
- //! of the reversed deque.
- //!
- //! <b>Throws</b>: Nothing.
- //!
- //! <b>Complexity</b>: Constant.
- reverse_iterator rend() BOOST_CONTAINER_NOEXCEPT
- { return reverse_iterator(this->members_.m_start); }
-
- //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
- //! of the reversed deque.
- //!
- //! <b>Throws</b>: Nothing.
- //!
- //! <b>Complexity</b>: Constant.
- const_reverse_iterator rbegin() const BOOST_CONTAINER_NOEXCEPT
- { return const_reverse_iterator(this->members_.m_finish); }
-
- //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
- //! of the reversed deque.
- //!
- //! <b>Throws</b>: Nothing.
- //!
- //! <b>Complexity</b>: Constant.
- const_reverse_iterator rend() const BOOST_CONTAINER_NOEXCEPT
- { return const_reverse_iterator(this->members_.m_start); }
-
- //! <b>Effects</b>: Returns a const_iterator to the first element contained in the deque.
- //!
- //! <b>Throws</b>: Nothing.
- //!
- //! <b>Complexity</b>: Constant.
- const_iterator cbegin() const BOOST_CONTAINER_NOEXCEPT
- { return this->members_.m_start; }
-
- //! <b>Effects</b>: Returns a const_iterator to the end of the deque.
- //!
- //! <b>Throws</b>: Nothing.
- //!
- //! <b>Complexity</b>: Constant.
- const_iterator cend() const BOOST_CONTAINER_NOEXCEPT
- { return this->members_.m_finish; }
-
- //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
- //! of the reversed deque.
- //!
- //! <b>Throws</b>: Nothing.
- //!
- //! <b>Complexity</b>: Constant.
- const_reverse_iterator crbegin() const BOOST_CONTAINER_NOEXCEPT
- { return const_reverse_iterator(this->members_.m_finish); }
-
- //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
- //! of the reversed deque.
- //!
- //! <b>Throws</b>: Nothing.
- //!
- //! <b>Complexity</b>: Constant.
- const_reverse_iterator crend() const BOOST_CONTAINER_NOEXCEPT
- { return const_reverse_iterator(this->members_.m_start); }
-
- //! <b>Requires</b>: size() > n.
- //!
- //! <b>Effects</b>: Returns a reference to the nth element
- //! from the beginning of the container.
- //!
- //! <b>Throws</b>: Nothing.
- //!
- //! <b>Complexity</b>: Constant.
- reference operator[](size_type n) BOOST_CONTAINER_NOEXCEPT
- { return this->members_.m_start[difference_type(n)]; }
-
- //! <b>Requires</b>: size() > n.
- //!
- //! <b>Effects</b>: Returns a const reference to the nth element
- //! from the beginning of the container.
- //!
- //! <b>Throws</b>: Nothing.
- //!
- //! <b>Complexity</b>: Constant.
- const_reference operator[](size_type n) const BOOST_CONTAINER_NOEXCEPT
- { return this->members_.m_start[difference_type(n)]; }
-
- //! <b>Requires</b>: size() > n.
- //!
- //! <b>Effects</b>: Returns a reference to the nth element
- //! from the beginning of the container.
- //!
- //! <b>Throws</b>: std::range_error if n >= size()
- //!
- //! <b>Complexity</b>: Constant.
- reference at(size_type n)
- { this->priv_range_check(n); return (*this)[n]; }
-
- //! <b>Requires</b>: size() > n.
- //!
- //! <b>Effects</b>: Returns a const reference to the nth element
- //! from the beginning of the container.
- //!
- //! <b>Throws</b>: std::range_error if n >= size()
- //!
- //! <b>Complexity</b>: Constant.
- const_reference at(size_type n) const
- { this->priv_range_check(n); return (*this)[n]; }
-
- //! <b>Requires</b>: !empty()
- //!
- //! <b>Effects</b>: Returns a reference to the first
- //! element of the container.
- //!
- //! <b>Throws</b>: Nothing.
- //!
- //! <b>Complexity</b>: Constant.
- reference front() BOOST_CONTAINER_NOEXCEPT
- { return *this->members_.m_start; }
-
- //! <b>Requires</b>: !empty()
- //!
- //! <b>Effects</b>: Returns a const reference to the first element
- //! from the beginning of the container.
- //!
- //! <b>Throws</b>: Nothing.
- //!
- //! <b>Complexity</b>: Constant.
- const_reference front() const BOOST_CONTAINER_NOEXCEPT
- { return *this->members_.m_start; }
-
- //! <b>Requires</b>: !empty()
- //!
- //! <b>Effects</b>: Returns a reference to the last
- //! element of the container.
- //!
- //! <b>Throws</b>: Nothing.
- //!
- //! <b>Complexity</b>: Constant.
- reference back() BOOST_CONTAINER_NOEXCEPT
- { return *(end()-1); }
-
- //! <b>Requires</b>: !empty()
- //!
- //! <b>Effects</b>: Returns a const reference to the last
- //! element of the container.
- //!
- //! <b>Throws</b>: Nothing.
- //!
- //! <b>Complexity</b>: Constant.
- const_reference back() const BOOST_CONTAINER_NOEXCEPT
- { return *(cend()-1); }
-
- //! <b>Effects</b>: Returns the number of the elements contained in the deque.
- //!
- //! <b>Throws</b>: Nothing.
- //!
- //! <b>Complexity</b>: Constant.
- size_type size() const BOOST_CONTAINER_NOEXCEPT
- { return this->members_.m_finish - this->members_.m_start; }
-
- //! <b>Effects</b>: Returns the largest possible size of the deque.
- //!
- //! <b>Throws</b>: Nothing.
- //!
- //! <b>Complexity</b>: Constant.
- size_type max_size() const BOOST_CONTAINER_NOEXCEPT
- { return allocator_traits_type::max_size(this->alloc()); }
-
- //! <b>Effects</b>: Returns true if the deque contains no elements.
- //!
- //! <b>Throws</b>: Nothing.
- //!
- //! <b>Complexity</b>: Constant.
- bool empty() const BOOST_CONTAINER_NOEXCEPT
- { return this->members_.m_finish == this->members_.m_start; }
+ //////////////////////////////////////////////
+ //
+ // construct/copy/destroy
+ //
+ //////////////////////////////////////////////
//! <b>Effects</b>: Default constructors a deque.
//!
@@ -838,33 +537,50 @@ class deque : protected deque_base<T, A>
//! <b>Effects</b>: Constructs a deque taking the allocator as parameter.
//!
- //! <b>Throws</b>: If allocator_type's copy constructor throws.
+ //! <b>Throws</b>: Nothing
//!
//! <b>Complexity</b>: Constant.
- explicit deque(const allocator_type& a)
+ explicit deque(const allocator_type& a) BOOST_CONTAINER_NOEXCEPT
: Base(a)
{}
//! <b>Effects</b>: Constructs a deque that will use a copy of allocator a
- //! and inserts n default contructed values.
+ //! and inserts n value initialized values.
//!
- //! <b>Throws</b>: If allocator_type's default constructor or copy constructor
- //! throws or T's default or copy constructor throws.
+ //! <b>Throws</b>: If allocator_type's default constructor
+ //! throws or T's value initialization throws.
//!
//! <b>Complexity</b>: Linear to n.
explicit deque(size_type n)
: Base(n, allocator_type())
{
- container_detail::default_construct_aux_proxy<A, iterator> proxy(this->alloc(), n);
- proxy.uninitialized_copy_remaining_to(this->begin());
+ container_detail::insert_value_initialized_n_proxy<Allocator, iterator> proxy;
+ proxy.uninitialized_copy_n_and_update(this->alloc(), this->begin(), n);
+ //deque_base will deallocate in case of exception...
+ }
+
+ //! <b>Effects</b>: Constructs a deque that will use a copy of allocator a
+ //! and inserts n default initialized values.
+ //!
+ //! <b>Throws</b>: If allocator_type's default constructor
+ //! throws or T's default initialization or copy constructor throws.
+ //!
+ //! <b>Complexity</b>: Linear to n.
+ //!
+ //! <b>Note</b>: Non-standard extension
+ deque(size_type n, default_init_t)
+ : Base(n, allocator_type())
+ {
+ container_detail::insert_default_initialized_n_proxy<Allocator, iterator> proxy;
+ proxy.uninitialized_copy_n_and_update(this->alloc(), this->begin(), n);
//deque_base will deallocate in case of exception...
}
//! <b>Effects</b>: Constructs a deque that will use a copy of allocator a
//! and inserts n copies of value.
//!
- //! <b>Throws</b>: If allocator_type's default constructor or copy constructor
- //! throws or T's default or copy constructor throws.
+ //! <b>Throws</b>: If allocator_type's default constructor
+ //! throws or T's copy constructor throws.
//!
//! <b>Complexity</b>: Linear to n.
deque(size_type n, const value_type& value,
@@ -872,6 +588,42 @@ class deque : protected deque_base<T, A>
: Base(n, a)
{ this->priv_fill_initialize(value); }
+ //! <b>Effects</b>: Constructs a deque that will use a copy of allocator a
+ //! and inserts a copy of the range [first, last) in the deque.
+ //!
+ //! <b>Throws</b>: If allocator_type's default constructor
+ //! throws or T's constructor taking a dereferenced InIt throws.
+ //!
+ //! <b>Complexity</b>: Linear to the range [first, last).
+ template <class InIt>
+ deque(InIt first, InIt last, const allocator_type& a = allocator_type()
+ #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
+ , typename container_detail::enable_if_c
+ < !container_detail::is_convertible<InIt, size_type>::value
+ >::type * = 0
+ #endif
+ )
+ : Base(a)
+ {
+ typedef typename std::iterator_traits<InIt>::iterator_category ItCat;
+ this->priv_range_initialize(first, last, ItCat());
+ }
+
+#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
+ //! <b>Effects</b>: Constructs a deque that will use a copy of allocator a
+ //! and inserts a copy of the range [il.begin(), il.end()) in the deque.
+ //!
+ //! <b>Throws</b>: If allocator_type's default constructor
+ //! throws or T's constructor taking a dereferenced std::initializer_list iterator throws.
+ //!
+ //! <b>Complexity</b>: Linear to the range [il.begin(), il.end()).
+ deque(std::initializer_list<value_type> il, const allocator_type& a = allocator_type())
+ : Base(a)
+ {
+ this->priv_range_initialize(il.begin(), il.end(), std::input_iterator_tag());
+ }
+#endif
+
//! <b>Effects</b>: Copy constructs a deque.
//!
//! <b>Postcondition</b>: x == *this.
@@ -936,23 +688,6 @@ class deque : protected deque_base<T, A>
}
}
- //! <b>Effects</b>: Constructs a deque that will use a copy of allocator a
- //! and inserts a copy of the range [first, last) in the deque.
- //!
- //! <b>Throws</b>: If allocator_type's default constructor or copy constructor
- //! throws or T's constructor taking an dereferenced InIt throws.
- //!
- //! <b>Complexity</b>: Linear to the range [first, last).
- template <class InpIt>
- deque(InpIt first, InpIt last, const allocator_type& a = allocator_type())
- : Base(a)
- {
- //Dispatch depending on integer/iterator
- const bool aux_boolean = container_detail::is_convertible<InpIt, size_type>::value;
- typedef container_detail::bool_<aux_boolean> Result;
- this->priv_initialize_dispatch(first, last, Result());
- }
-
//! <b>Effects</b>: Destroys the deque. All stored values are destroyed
//! and used memory is deallocated.
//!
@@ -961,7 +696,7 @@ class deque : protected deque_base<T, A>
//! <b>Complexity</b>: Linear to the number of elements.
~deque() BOOST_CONTAINER_NOEXCEPT
{
- priv_destroy_range(this->members_.m_start, this->members_.m_finish);
+ this->priv_destroy_range(this->members_.m_start, this->members_.m_finish);
}
//! <b>Effects</b>: Makes *this contain the same elements as x.
@@ -990,52 +725,58 @@ class deque : protected deque_base<T, A>
return *this;
}
- //! <b>Effects</b>: Move assignment. All mx's values are transferred to *this.
- //!
- //! <b>Postcondition</b>: x.empty(). *this contains a the elements x had
- //! before the function.
+ //! <b>Effects</b>: Move assignment. All x's values are transferred to *this.
//!
- //! <b>Throws</b>: If allocator_type's copy constructor throws.
+ //! <b>Throws</b>: If allocator_traits_type::propagate_on_container_move_assignment
+ //! is false and (allocation throws or value_type's move constructor throws)
//!
- //! <b>Complexity</b>: Linear.
+ //! <b>Complexity</b>: Constant if allocator_traits_type::
+ //! propagate_on_container_move_assignment is true or
+ //! this->get>allocator() == x.get_allocator(). Linear otherwise.
deque& operator= (BOOST_RV_REF(deque) x)
- {
- if (&x != this){
- allocator_type &this_alloc = this->alloc();
- allocator_type &x_alloc = x.alloc();
- //If allocators are equal we can just swap pointers
- if(this_alloc == x_alloc){
- //Destroy objects but retain memory in case x reuses it in the future
- this->clear();
- this->swap_members(x);
- //Move allocator if needed
- container_detail::bool_<allocator_traits_type::
- propagate_on_container_move_assignment::value> flag;
- container_detail::move_alloc(this_alloc, x_alloc, flag);
- container_detail::move_alloc(this->ptr_alloc(), x.ptr_alloc(), flag);
- }
- //If unequal allocators, then do a one by one move
- else{
- typedef typename std::iterator_traits<iterator>::iterator_category ItCat;
- this->assign( boost::make_move_iterator(x.begin())
- , boost::make_move_iterator(x.end()));
- }
+ BOOST_CONTAINER_NOEXCEPT_IF(allocator_traits_type::propagate_on_container_move_assignment::value)
+ {
+ BOOST_ASSERT(this != &x);
+ allocator_type &this_alloc = this->alloc();
+ allocator_type &x_alloc = x.alloc();
+ const bool propagate_alloc = allocator_traits_type::
+ propagate_on_container_move_assignment::value;
+ container_detail::bool_<propagate_alloc> flag;
+ const bool allocators_equal = this_alloc == x_alloc; (void)allocators_equal;
+ //Resources can be transferred if both allocators are
+ //going to be equal after this function (either propagated or already equal)
+ if(propagate_alloc || allocators_equal){
+ //Destroy objects but retain memory in case x reuses it in the future
+ this->clear();
+ //Move allocator if needed
+ container_detail::move_alloc(this_alloc, x_alloc, flag);
+ container_detail::move_alloc(this->ptr_alloc(), x.ptr_alloc(), flag);
+ //Nothrow swap
+ this->swap_members(x);
+ }
+ //Else do a one by one move
+ else{
+ this->assign( boost::make_move_iterator(x.begin())
+ , boost::make_move_iterator(x.end()));
}
return *this;
}
- //! <b>Effects</b>: Swaps the contents of *this and x.
+#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
+ //! <b>Effects</b>: Makes *this contain the same elements as il.
//!
- //! <b>Throws</b>: Nothing.
+ //! <b>Postcondition</b>: this->size() == il.size(). *this contains a copy
+ //! of each of x's elements.
//!
- //! <b>Complexity</b>: Constant.
- void swap(deque &x)
+ //! <b>Throws</b>: If memory allocation throws or T's copy constructor throws.
+ //!
+ //! <b>Complexity</b>: Linear to the number of elements in il.
+ deque& operator=(std::initializer_list<value_type> il)
{
- this->swap_members(x);
- container_detail::bool_<allocator_traits_type::propagate_on_container_swap::value> flag;
- container_detail::swap_alloc(this->alloc(), x.alloc(), flag);
- container_detail::swap_alloc(this->ptr_alloc(), x.ptr_alloc(), flag);
+ this->assign(il.begin(), il.end());
+ return *this;
}
+#endif
//! <b>Effects</b>: Assigns the n copies of val to *this.
//!
@@ -1043,207 +784,462 @@ class deque : protected deque_base<T, A>
//!
//! <b>Complexity</b>: Linear to n.
void assign(size_type n, const T& val)
- { this->priv_fill_assign(n, val); }
+ {
+ typedef constant_iterator<value_type, difference_type> c_it;
+ this->assign(c_it(val, n), c_it());
+ }
//! <b>Effects</b>: Assigns the the range [first, last) to *this.
//!
//! <b>Throws</b>: If memory allocation throws or
- //! T's constructor from dereferencing InpIt throws.
+ //! T's constructor from dereferencing InIt throws.
//!
//! <b>Complexity</b>: Linear to n.
- template <class InpIt>
- void assign(InpIt first, InpIt last)
- {
- //Dispatch depending on integer/iterator
- const bool aux_boolean = container_detail::is_convertible<InpIt, size_type>::value;
- typedef container_detail::bool_<aux_boolean> Result;
- this->priv_assign_dispatch(first, last, Result());
+ template <class InIt>
+ void assign(InIt first, InIt last
+ #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
+ , typename container_detail::enable_if_c
+ < !container_detail::is_convertible<InIt, size_type>::value
+ && container_detail::is_input_iterator<InIt>::value
+ >::type * = 0
+ #endif
+ )
+ {
+ iterator cur = this->begin();
+ for ( ; first != last && cur != end(); ++cur, ++first){
+ *cur = *first;
+ }
+ if (first == last){
+ this->erase(cur, this->cend());
+ }
+ else{
+ this->insert(this->cend(), first, last);
+ }
}
- #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
- //! <b>Effects</b>: Inserts a copy of x at the end of the deque.
+ #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
+ template <class FwdIt>
+ void assign(FwdIt first, FwdIt last
+ , typename container_detail::enable_if_c
+ < !container_detail::is_convertible<FwdIt, size_type>::value
+ && !container_detail::is_input_iterator<FwdIt>::value
+ >::type * = 0
+ )
+ {
+ const size_type len = std::distance(first, last);
+ if (len > size()) {
+ FwdIt mid = first;
+ std::advance(mid, this->size());
+ boost::container::copy(first, mid, begin());
+ this->insert(this->cend(), mid, last);
+ }
+ else{
+ this->erase(boost::container::copy(first, last, this->begin()), cend());
+ }
+ }
+ #endif
+
+#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
+ //! <b>Effects</b>: Assigns the the range [il.begin(), il.end()) to *this.
//!
//! <b>Throws</b>: If memory allocation throws or
- //! T's copy constructor throws.
+ //! T's constructor from dereferencing std::initializer_list iterator throws.
//!
- //! <b>Complexity</b>: Amortized constant time.
- void push_back(const T &x);
+ //! <b>Complexity</b>: Linear to il.size().
+ void assign(std::initializer_list<value_type> il)
+ { this->assign(il.begin(), il.end()); }
+#endif
- //! <b>Effects</b>: Constructs a new element in the end of the deque
- //! and moves the resources of mx to this new element.
+ //! <b>Effects</b>: Returns a copy of the internal allocator.
//!
- //! <b>Throws</b>: If memory allocation throws.
+ //! <b>Throws</b>: If allocator's copy constructor throws.
//!
- //! <b>Complexity</b>: Amortized constant time.
- void push_back(T &&x);
- #else
- BOOST_MOVE_CONVERSION_AWARE_CATCH(push_back, T, void, priv_push_back)
- #endif
+ //! <b>Complexity</b>: Constant.
+ allocator_type get_allocator() const BOOST_CONTAINER_NOEXCEPT
+ { return Base::alloc(); }
- #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
- //! <b>Effects</b>: Inserts a copy of x at the front of the deque.
+ //! <b>Effects</b>: Returns a reference to the internal allocator.
//!
- //! <b>Throws</b>: If memory allocation throws or
- //! T's copy constructor throws.
+ //! <b>Throws</b>: Nothing
//!
- //! <b>Complexity</b>: Amortized constant time.
- void push_front(const T &x);
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Note</b>: Non-standard extension.
+ const stored_allocator_type &get_stored_allocator() const BOOST_CONTAINER_NOEXCEPT
+ { return Base::alloc(); }
- //! <b>Effects</b>: Constructs a new element in the front of the deque
- //! and moves the resources of mx to this new element.
+ //////////////////////////////////////////////
+ //
+ // iterators
+ //
+ //////////////////////////////////////////////
+
+ //! <b>Effects</b>: Returns a reference to the internal allocator.
//!
- //! <b>Throws</b>: If memory allocation throws.
+ //! <b>Throws</b>: Nothing
//!
- //! <b>Complexity</b>: Amortized constant time.
- void push_front(T &&x);
- #else
- BOOST_MOVE_CONVERSION_AWARE_CATCH(push_front, T, void, priv_push_front)
- #endif
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Note</b>: Non-standard extension.
+ stored_allocator_type &get_stored_allocator() BOOST_CONTAINER_NOEXCEPT
+ { return Base::alloc(); }
- //! <b>Effects</b>: Removes the last element from the deque.
+ //! <b>Effects</b>: Returns an iterator to the first element contained in the deque.
//!
//! <b>Throws</b>: Nothing.
//!
- //! <b>Complexity</b>: Constant time.
- void pop_back() BOOST_CONTAINER_NOEXCEPT
+ //! <b>Complexity</b>: Constant.
+ iterator begin() BOOST_CONTAINER_NOEXCEPT
+ { return this->members_.m_start; }
+
+ //! <b>Effects</b>: Returns a const_iterator to the first element contained in the deque.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ const_iterator begin() const BOOST_CONTAINER_NOEXCEPT
+ { return this->members_.m_start; }
+
+ //! <b>Effects</b>: Returns an iterator to the end of the deque.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ iterator end() BOOST_CONTAINER_NOEXCEPT
+ { return this->members_.m_finish; }
+
+ //! <b>Effects</b>: Returns a const_iterator to the end of the deque.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ const_iterator end() const BOOST_CONTAINER_NOEXCEPT
+ { return this->members_.m_finish; }
+
+ //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning
+ //! of the reversed deque.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ reverse_iterator rbegin() BOOST_CONTAINER_NOEXCEPT
+ { return reverse_iterator(this->members_.m_finish); }
+
+ //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
+ //! of the reversed deque.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ const_reverse_iterator rbegin() const BOOST_CONTAINER_NOEXCEPT
+ { return const_reverse_iterator(this->members_.m_finish); }
+
+ //! <b>Effects</b>: Returns a reverse_iterator pointing to the end
+ //! of the reversed deque.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ reverse_iterator rend() BOOST_CONTAINER_NOEXCEPT
+ { return reverse_iterator(this->members_.m_start); }
+
+ //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
+ //! of the reversed deque.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ const_reverse_iterator rend() const BOOST_CONTAINER_NOEXCEPT
+ { return const_reverse_iterator(this->members_.m_start); }
+
+ //! <b>Effects</b>: Returns a const_iterator to the first element contained in the deque.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ const_iterator cbegin() const BOOST_CONTAINER_NOEXCEPT
+ { return this->members_.m_start; }
+
+ //! <b>Effects</b>: Returns a const_iterator to the end of the deque.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ const_iterator cend() const BOOST_CONTAINER_NOEXCEPT
+ { return this->members_.m_finish; }
+
+ //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
+ //! of the reversed deque.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ const_reverse_iterator crbegin() const BOOST_CONTAINER_NOEXCEPT
+ { return const_reverse_iterator(this->members_.m_finish); }
+
+ //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
+ //! of the reversed deque.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ const_reverse_iterator crend() const BOOST_CONTAINER_NOEXCEPT
+ { return const_reverse_iterator(this->members_.m_start); }
+
+ //////////////////////////////////////////////
+ //
+ // capacity
+ //
+ //////////////////////////////////////////////
+
+ //! <b>Effects</b>: Returns true if the deque contains no elements.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ bool empty() const BOOST_CONTAINER_NOEXCEPT
+ { return this->members_.m_finish == this->members_.m_start; }
+
+ //! <b>Effects</b>: Returns the number of the elements contained in the deque.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ size_type size() const BOOST_CONTAINER_NOEXCEPT
+ { return this->members_.m_finish - this->members_.m_start; }
+
+ //! <b>Effects</b>: Returns the largest possible size of the deque.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ size_type max_size() const BOOST_CONTAINER_NOEXCEPT
+ { return allocator_traits_type::max_size(this->alloc()); }
+
+ //! <b>Effects</b>: Inserts or erases elements at the end such that
+ //! the size becomes n. New elements are value initialized.
+ //!
+ //! <b>Throws</b>: If memory allocation throws, or T's constructor throws.
+ //!
+ //! <b>Complexity</b>: Linear to the difference between size() and new_size.
+ void resize(size_type new_size)
{
- if (this->members_.m_finish.m_cur != this->members_.m_finish.m_first) {
- --this->members_.m_finish.m_cur;
- allocator_traits_type::destroy
- ( this->alloc()
- , container_detail::to_raw_pointer(this->members_.m_finish.m_cur)
- );
+ const size_type len = size();
+ if (new_size < len)
+ this->priv_erase_last_n(len - new_size);
+ else{
+ const size_type n = new_size - this->size();
+ container_detail::insert_value_initialized_n_proxy<Allocator, iterator> proxy;
+ priv_insert_back_aux_impl(n, proxy);
}
- else
- this->priv_pop_back_aux();
}
- //! <b>Effects</b>: Removes the first element from the deque.
+ //! <b>Effects</b>: Inserts or erases elements at the end such that
+ //! the size becomes n. New elements are default initialized.
//!
- //! <b>Throws</b>: Nothing.
+ //! <b>Throws</b>: If memory allocation throws, or T's constructor throws.
//!
- //! <b>Complexity</b>: Constant time.
- void pop_front() BOOST_CONTAINER_NOEXCEPT
+ //! <b>Complexity</b>: Linear to the difference between size() and new_size.
+ //!
+ //! <b>Note</b>: Non-standard extension
+ void resize(size_type new_size, default_init_t)
{
- if (this->members_.m_start.m_cur != this->members_.m_start.m_last - 1) {
- allocator_traits_type::destroy
- ( this->alloc()
- , container_detail::to_raw_pointer(this->members_.m_start.m_cur)
- );
- ++this->members_.m_start.m_cur;
+ const size_type len = size();
+ if (new_size < len)
+ this->priv_erase_last_n(len - new_size);
+ else{
+ const size_type n = new_size - this->size();
+ container_detail::insert_default_initialized_n_proxy<Allocator, iterator> proxy;
+ priv_insert_back_aux_impl(n, proxy);
}
+ }
+
+ //! <b>Effects</b>: Inserts or erases elements at the end such that
+ //! the size becomes n. New elements are copy constructed from x.
+ //!
+ //! <b>Throws</b>: If memory allocation throws, or T's copy constructor throws.
+ //!
+ //! <b>Complexity</b>: Linear to the difference between size() and new_size.
+ void resize(size_type new_size, const value_type& x)
+ {
+ const size_type len = size();
+ if (new_size < len)
+ this->erase(this->members_.m_start + new_size, this->members_.m_finish);
else
- this->priv_pop_front_aux();
+ this->insert(this->members_.m_finish, new_size - len, x);
}
- #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
+ //! <b>Effects</b>: Tries to deallocate the excess of memory created
+ //! with previous allocations. The size of the deque is unchanged
+ //!
+ //! <b>Throws</b>: If memory allocation throws.
+ //!
+ //! <b>Complexity</b>: Constant.
+ void shrink_to_fit()
+ {
+ //This deque implementation already
+ //deallocates excess nodes when erasing
+ //so there is nothing to do except for
+ //empty deque
+ if(this->empty()){
+ this->priv_clear_map();
+ }
+ }
- //! <b>Requires</b>: position must be a valid iterator of *this.
+ //////////////////////////////////////////////
+ //
+ // element access
+ //
+ //////////////////////////////////////////////
+
+ //! <b>Requires</b>: !empty()
//!
- //! <b>Effects</b>: Insert a copy of x before position.
+ //! <b>Effects</b>: Returns a reference to the first
+ //! element of the container.
//!
- //! <b>Throws</b>: If memory allocation throws or x's copy constructor throws.
+ //! <b>Throws</b>: Nothing.
//!
- //! <b>Complexity</b>: If position is end(), amortized constant time
- //! Linear time otherwise.
- iterator insert(const_iterator position, const T &x);
+ //! <b>Complexity</b>: Constant.
+ reference front() BOOST_CONTAINER_NOEXCEPT
+ { return *this->members_.m_start; }
- //! <b>Requires</b>: position must be a valid iterator of *this.
+ //! <b>Requires</b>: !empty()
//!
- //! <b>Effects</b>: Insert a new element before position with mx's resources.
+ //! <b>Effects</b>: Returns a const reference to the first element
+ //! from the beginning of the container.
//!
- //! <b>Throws</b>: If memory allocation throws.
+ //! <b>Throws</b>: Nothing.
//!
- //! <b>Complexity</b>: If position is end(), amortized constant time
- //! Linear time otherwise.
- iterator insert(const_iterator position, T &&x);
- #else
- BOOST_MOVE_CONVERSION_AWARE_CATCH_1ARG(insert, T, iterator, priv_insert, const_iterator)
- #endif
+ //! <b>Complexity</b>: Constant.
+ const_reference front() const BOOST_CONTAINER_NOEXCEPT
+ { return *this->members_.m_start; }
- //! <b>Requires</b>: pos must be a valid iterator of *this.
+ //! <b>Requires</b>: !empty()
//!
- //! <b>Effects</b>: Insert n copies of x before pos.
+ //! <b>Effects</b>: Returns a reference to the last
+ //! element of the container.
//!
- //! <b>Throws</b>: If memory allocation throws or T's copy constructor throws.
+ //! <b>Throws</b>: Nothing.
//!
- //! <b>Complexity</b>: Linear to n.
- void insert(const_iterator pos, size_type n, const value_type& x)
- { this->priv_fill_insert(pos, n, x); }
+ //! <b>Complexity</b>: Constant.
+ reference back() BOOST_CONTAINER_NOEXCEPT
+ { return *(end()-1); }
- //! <b>Requires</b>: pos must be a valid iterator of *this.
+ //! <b>Requires</b>: !empty()
//!
- //! <b>Effects</b>: Insert a copy of the [first, last) range before pos.
+ //! <b>Effects</b>: Returns a const reference to the last
+ //! element of the container.
//!
- //! <b>Throws</b>: If memory allocation throws, T's constructor from a
- //! dereferenced InpIt throws or T's copy constructor throws.
+ //! <b>Throws</b>: Nothing.
//!
- //! <b>Complexity</b>: Linear to std::distance [first, last).
- template <class InpIt>
- void insert(const_iterator pos, InpIt first, InpIt last)
- {
- //Dispatch depending on integer/iterator
- const bool aux_boolean = container_detail::is_convertible<InpIt, size_type>::value;
- typedef container_detail::bool_<aux_boolean> Result;
- this->priv_insert_dispatch(pos, first, last, Result());
- }
+ //! <b>Complexity</b>: Constant.
+ const_reference back() const BOOST_CONTAINER_NOEXCEPT
+ { return *(cend()-1); }
+
+ //! <b>Requires</b>: size() > n.
+ //!
+ //! <b>Effects</b>: Returns a reference to the nth element
+ //! from the beginning of the container.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ reference operator[](size_type n) BOOST_CONTAINER_NOEXCEPT
+ { return this->members_.m_start[difference_type(n)]; }
+
+ //! <b>Requires</b>: size() > n.
+ //!
+ //! <b>Effects</b>: Returns a const reference to the nth element
+ //! from the beginning of the container.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ const_reference operator[](size_type n) const BOOST_CONTAINER_NOEXCEPT
+ { return this->members_.m_start[difference_type(n)]; }
+
+ //! <b>Requires</b>: size() > n.
+ //!
+ //! <b>Effects</b>: Returns a reference to the nth element
+ //! from the beginning of the container.
+ //!
+ //! <b>Throws</b>: std::range_error if n >= size()
+ //!
+ //! <b>Complexity</b>: Constant.
+ reference at(size_type n)
+ { this->priv_range_check(n); return (*this)[n]; }
+
+ //! <b>Requires</b>: size() > n.
+ //!
+ //! <b>Effects</b>: Returns a const reference to the nth element
+ //! from the beginning of the container.
+ //!
+ //! <b>Throws</b>: std::range_error if n >= size()
+ //!
+ //! <b>Complexity</b>: Constant.
+ const_reference at(size_type n) const
+ { this->priv_range_check(n); return (*this)[n]; }
+
+ //////////////////////////////////////////////
+ //
+ // modifiers
+ //
+ //////////////////////////////////////////////
#if defined(BOOST_CONTAINER_PERFECT_FORWARDING) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
//! <b>Effects</b>: Inserts an object of type T constructed with
- //! std::forward<Args>(args)... in the end of the deque.
+ //! std::forward<Args>(args)... in the beginning of the deque.
//!
//! <b>Throws</b>: If memory allocation throws or the in-place constructor throws.
//!
//! <b>Complexity</b>: Amortized constant time
template <class... Args>
- void emplace_back(Args&&... args)
+ void emplace_front(Args&&... args)
{
- if(this->priv_push_back_simple_available()){
+ if(this->priv_push_front_simple_available()){
allocator_traits_type::construct
( this->alloc()
- , this->priv_push_back_simple_pos()
+ , this->priv_push_front_simple_pos()
, boost::forward<Args>(args)...);
- this->priv_push_back_simple_commit();
+ this->priv_push_front_simple_commit();
}
else{
- typedef container_detail::advanced_insert_aux_non_movable_emplace<A, iterator, Args...> type;
- type &&proxy = type(this->alloc(), boost::forward<Args>(args)...);
- this->priv_insert_back_aux_impl(1, proxy);
+ typedef container_detail::insert_non_movable_emplace_proxy<Allocator, iterator, Args...> type;
+ this->priv_insert_front_aux_impl(1, type(boost::forward<Args>(args)...));
}
}
//! <b>Effects</b>: Inserts an object of type T constructed with
- //! std::forward<Args>(args)... in the beginning of the deque.
+ //! std::forward<Args>(args)... in the end of the deque.
//!
//! <b>Throws</b>: If memory allocation throws or the in-place constructor throws.
//!
//! <b>Complexity</b>: Amortized constant time
template <class... Args>
- void emplace_front(Args&&... args)
+ void emplace_back(Args&&... args)
{
- if(this->priv_push_front_simple_available()){
+ if(this->priv_push_back_simple_available()){
allocator_traits_type::construct
( this->alloc()
- , this->priv_push_front_simple_pos()
+ , this->priv_push_back_simple_pos()
, boost::forward<Args>(args)...);
- this->priv_push_front_simple_commit();
+ this->priv_push_back_simple_commit();
}
else{
- typedef container_detail::advanced_insert_aux_non_movable_emplace<A, iterator, Args...> type;
- type &&proxy = type(this->alloc(), boost::forward<Args>(args)...);
- this->priv_insert_front_aux_impl(1, proxy);
+ typedef container_detail::insert_non_movable_emplace_proxy<Allocator, iterator, Args...> type;
+ this->priv_insert_back_aux_impl(1, type(boost::forward<Args>(args)...));
}
}
- //! <b>Requires</b>: position must be a valid iterator of *this.
+ //! <b>Requires</b>: p must be a valid iterator of *this.
//!
//! <b>Effects</b>: Inserts an object of type T constructed with
- //! std::forward<Args>(args)... before position
+ //! std::forward<Args>(args)... before p
//!
//! <b>Throws</b>: If memory allocation throws or the in-place constructor throws.
//!
- //! <b>Complexity</b>: If position is end(), amortized constant time
+ //! <b>Complexity</b>: If p is end(), amortized constant time
//! Linear time otherwise.
template <class... Args>
iterator emplace(const_iterator p, Args&&... args)
@@ -1257,11 +1253,8 @@ class deque : protected deque_base<T, A>
return (this->end()-1);
}
else{
- size_type n = p - this->cbegin();
- typedef container_detail::advanced_insert_aux_emplace<A, iterator, Args...> type;
- type &&proxy = type(this->alloc(), boost::forward<Args>(args)...);
- this->priv_insert_aux_impl(p, 1, proxy);
- return iterator(this->begin() + n);
+ typedef container_detail::insert_emplace_proxy<Allocator, iterator, Args...> type;
+ return this->priv_insert_aux_impl(p, 1, type(boost::forward<Args>(args)...));
}
}
@@ -1269,41 +1262,39 @@ class deque : protected deque_base<T, A>
//advanced_insert_int.hpp includes all necessary preprocessor machinery...
#define BOOST_PP_LOCAL_MACRO(n) \
- BOOST_PP_EXPR_IF(n, template<) BOOST_PP_ENUM_PARAMS(n, class P) BOOST_PP_EXPR_IF(n, >) \
- void emplace_back(BOOST_PP_ENUM(n, BOOST_CONTAINER_PP_PARAM_LIST, _)) \
+ BOOST_PP_EXPR_IF(n, template<) BOOST_PP_ENUM_PARAMS(n, class P) BOOST_PP_EXPR_IF(n, > ) \
+ void emplace_front(BOOST_PP_ENUM(n, BOOST_CONTAINER_PP_PARAM_LIST, _)) \
{ \
- if(priv_push_back_simple_available()){ \
+ if(priv_push_front_simple_available()){ \
allocator_traits_type::construct \
( this->alloc() \
- , this->priv_push_back_simple_pos() \
+ , this->priv_push_front_simple_pos() \
BOOST_PP_ENUM_TRAILING(n, BOOST_CONTAINER_PP_PARAM_FORWARD, _)); \
- priv_push_back_simple_commit(); \
+ priv_push_front_simple_commit(); \
} \
else{ \
- container_detail::BOOST_PP_CAT(BOOST_PP_CAT( \
- advanced_insert_aux_non_movable_emplace, n), arg) \
- <A, iterator BOOST_PP_ENUM_TRAILING_PARAMS(n, P)> proxy \
- (this->alloc() BOOST_PP_ENUM_TRAILING(n, BOOST_CONTAINER_PP_PARAM_FORWARD, _)); \
- priv_insert_back_aux_impl(1, proxy); \
+ typedef container_detail::BOOST_PP_CAT(insert_non_movable_emplace_proxy_arg, n) \
+ <Allocator, iterator BOOST_PP_ENUM_TRAILING_PARAMS(n, P)> type; \
+ priv_insert_front_aux_impl \
+ (1, type(BOOST_PP_ENUM(n, BOOST_CONTAINER_PP_PARAM_FORWARD, _))); \
} \
} \
\
- BOOST_PP_EXPR_IF(n, template<) BOOST_PP_ENUM_PARAMS(n, class P) BOOST_PP_EXPR_IF(n, > ) \
- void emplace_front(BOOST_PP_ENUM(n, BOOST_CONTAINER_PP_PARAM_LIST, _)) \
+ BOOST_PP_EXPR_IF(n, template<) BOOST_PP_ENUM_PARAMS(n, class P) BOOST_PP_EXPR_IF(n, >) \
+ void emplace_back(BOOST_PP_ENUM(n, BOOST_CONTAINER_PP_PARAM_LIST, _)) \
{ \
- if(priv_push_front_simple_available()){ \
+ if(priv_push_back_simple_available()){ \
allocator_traits_type::construct \
( this->alloc() \
- , this->priv_push_front_simple_pos() \
+ , this->priv_push_back_simple_pos() \
BOOST_PP_ENUM_TRAILING(n, BOOST_CONTAINER_PP_PARAM_FORWARD, _)); \
- priv_push_front_simple_commit(); \
+ priv_push_back_simple_commit(); \
} \
else{ \
- container_detail::BOOST_PP_CAT(BOOST_PP_CAT \
- (advanced_insert_aux_non_movable_emplace, n), arg) \
- <A, iterator BOOST_PP_ENUM_TRAILING_PARAMS(n, P)> proxy \
- (this->alloc() BOOST_PP_ENUM_TRAILING(n, BOOST_CONTAINER_PP_PARAM_FORWARD, _)); \
- priv_insert_front_aux_impl(1, proxy); \
+ typedef container_detail::BOOST_PP_CAT(insert_non_movable_emplace_proxy_arg, n) \
+ <Allocator, iterator BOOST_PP_ENUM_TRAILING_PARAMS(n, P)> type; \
+ priv_insert_back_aux_impl \
+ (1, type(BOOST_PP_ENUM(n, BOOST_CONTAINER_PP_PARAM_FORWARD, _))); \
} \
} \
\
@@ -1320,12 +1311,10 @@ class deque : protected deque_base<T, A>
return (this->end()-1); \
} \
else{ \
- size_type pos_num = p - this->cbegin(); \
- container_detail::BOOST_PP_CAT(BOOST_PP_CAT(advanced_insert_aux_emplace, n), arg) \
- <A, iterator BOOST_PP_ENUM_TRAILING_PARAMS(n, P)> proxy \
- (this->alloc() BOOST_PP_ENUM_TRAILING(n, BOOST_CONTAINER_PP_PARAM_FORWARD, _)); \
- this->priv_insert_aux_impl(p, 1, proxy); \
- return iterator(this->begin() + pos_num); \
+ typedef container_detail::BOOST_PP_CAT(insert_emplace_proxy_arg, n) \
+ <Allocator, iterator BOOST_PP_ENUM_TRAILING_PARAMS(n, P)> type; \
+ return this->priv_insert_aux_impl \
+ (p, 1, type(BOOST_PP_ENUM(n, BOOST_CONTAINER_PP_PARAM_FORWARD, _))); \
} \
} \
//!
@@ -1334,40 +1323,188 @@ class deque : protected deque_base<T, A>
#endif //#ifdef BOOST_CONTAINER_PERFECT_FORWARDING
- //! <b>Effects</b>: Inserts or erases elements at the end such that
- //! the size becomes n. New elements are copy constructed from x.
+ #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
+ //! <b>Effects</b>: Inserts a copy of x at the front of the deque.
//!
- //! <b>Throws</b>: If memory allocation throws, or T's copy constructor throws.
+ //! <b>Throws</b>: If memory allocation throws or
+ //! T's copy constructor throws.
//!
- //! <b>Complexity</b>: Linear to the difference between size() and new_size.
- void resize(size_type new_size, const value_type& x)
+ //! <b>Complexity</b>: Amortized constant time.
+ void push_front(const T &x);
+
+ //! <b>Effects</b>: Constructs a new element in the front of the deque
+ //! and moves the resources of mx to this new element.
+ //!
+ //! <b>Throws</b>: If memory allocation throws.
+ //!
+ //! <b>Complexity</b>: Amortized constant time.
+ void push_front(T &&x);
+ #else
+ BOOST_MOVE_CONVERSION_AWARE_CATCH(push_front, T, void, priv_push_front)
+ #endif
+
+ #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
+ //! <b>Effects</b>: Inserts a copy of x at the end of the deque.
+ //!
+ //! <b>Throws</b>: If memory allocation throws or
+ //! T's copy constructor throws.
+ //!
+ //! <b>Complexity</b>: Amortized constant time.
+ void push_back(const T &x);
+
+ //! <b>Effects</b>: Constructs a new element in the end of the deque
+ //! and moves the resources of mx to this new element.
+ //!
+ //! <b>Throws</b>: If memory allocation throws.
+ //!
+ //! <b>Complexity</b>: Amortized constant time.
+ void push_back(T &&x);
+ #else
+ BOOST_MOVE_CONVERSION_AWARE_CATCH(push_back, T, void, priv_push_back)
+ #endif
+
+ #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
+
+ //! <b>Requires</b>: p must be a valid iterator of *this.
+ //!
+ //! <b>Effects</b>: Insert a copy of x before p.
+ //!
+ //! <b>Returns</b>: an iterator to the inserted element.
+ //!
+ //! <b>Throws</b>: If memory allocation throws or x's copy constructor throws.
+ //!
+ //! <b>Complexity</b>: If p is end(), amortized constant time
+ //! Linear time otherwise.
+ iterator insert(const_iterator p, const T &x);
+
+ //! <b>Requires</b>: p must be a valid iterator of *this.
+ //!
+ //! <b>Effects</b>: Insert a new element before p with mx's resources.
+ //!
+ //! <b>Returns</b>: an iterator to the inserted element.
+ //!
+ //! <b>Throws</b>: If memory allocation throws.
+ //!
+ //! <b>Complexity</b>: If p is end(), amortized constant time
+ //! Linear time otherwise.
+ iterator insert(const_iterator p, T &&x);
+ #else
+ BOOST_MOVE_CONVERSION_AWARE_CATCH_1ARG(insert, T, iterator, priv_insert, const_iterator, const_iterator)
+ #endif
+
+ //! <b>Requires</b>: pos must be a valid iterator of *this.
+ //!
+ //! <b>Effects</b>: Insert n copies of x before pos.
+ //!
+ //! <b>Returns</b>: an iterator to the first inserted element or pos if n is 0.
+ //!
+ //! <b>Throws</b>: If memory allocation throws or T's copy constructor throws.
+ //!
+ //! <b>Complexity</b>: Linear to n.
+ iterator insert(const_iterator pos, size_type n, const value_type& x)
{
- const size_type len = size();
- if (new_size < len)
- this->erase(this->members_.m_start + new_size, this->members_.m_finish);
+ typedef constant_iterator<value_type, difference_type> c_it;
+ return this->insert(pos, c_it(x, n), c_it());
+ }
+
+ //! <b>Requires</b>: pos must be a valid iterator of *this.
+ //!
+ //! <b>Effects</b>: Insert a copy of the [first, last) range before pos.
+ //!
+ //! <b>Returns</b>: an iterator to the first inserted element or pos if first == last.
+ //!
+ //! <b>Throws</b>: If memory allocation throws, T's constructor from a
+ //! dereferenced InIt throws or T's copy constructor throws.
+ //!
+ //! <b>Complexity</b>: Linear to std::distance [first, last).
+ template <class InIt>
+ iterator insert(const_iterator pos, InIt first, InIt last
+ #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
+ , typename container_detail::enable_if_c
+ < !container_detail::is_convertible<InIt, size_type>::value
+ && container_detail::is_input_iterator<InIt>::value
+ >::type * = 0
+ #endif
+ )
+ {
+ size_type n = 0;
+ iterator it(pos.unconst());
+ for(;first != last; ++first, ++n){
+ it = this->emplace(it, *first);
+ ++it;
+ }
+ it -= n;
+ return it;
+ }
+
+#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
+ //! <b>Requires</b>: pos must be a valid iterator of *this.
+ //!
+ //! <b>Effects</b>: Insert a copy of the [il.begin(), il.end()) range before pos.
+ //!
+ //! <b>Returns</b>: an iterator to the first inserted element or pos if il.begin() == il.end().
+ //!
+ //! <b>Throws</b>: If memory allocation throws, T's constructor from a
+ //! dereferenced std::initializer_list throws or T's copy constructor throws.
+ //!
+ //! <b>Complexity</b>: Linear to std::distance [il.begin(), il.end()).
+ iterator insert(const_iterator pos, std::initializer_list<value_type> il)
+ { return insert(pos, il.begin(), il.end()); }
+#endif
+
+ #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
+ template <class FwdIt>
+ iterator insert(const_iterator p, FwdIt first, FwdIt last
+ #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
+ , typename container_detail::enable_if_c
+ < !container_detail::is_convertible<FwdIt, size_type>::value
+ && !container_detail::is_input_iterator<FwdIt>::value
+ >::type * = 0
+ #endif
+ )
+ {
+ container_detail::insert_range_proxy<Allocator, FwdIt, iterator> proxy(first);
+ return priv_insert_aux_impl(p, (size_type)std::distance(first, last), proxy);
+ }
+ #endif
+
+ //! <b>Effects</b>: Removes the first element from the deque.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant time.
+ void pop_front() BOOST_CONTAINER_NOEXCEPT
+ {
+ if (this->members_.m_start.m_cur != this->members_.m_start.m_last - 1) {
+ allocator_traits_type::destroy
+ ( this->alloc()
+ , container_detail::to_raw_pointer(this->members_.m_start.m_cur)
+ );
+ ++this->members_.m_start.m_cur;
+ }
else
- this->insert(this->members_.m_finish, new_size - len, x);
+ this->priv_pop_front_aux();
}
- //! <b>Effects</b>: Inserts or erases elements at the end such that
- //! the size becomes n. New elements are default constructed.
+ //! <b>Effects</b>: Removes the last element from the deque.
//!
- //! <b>Throws</b>: If memory allocation throws, or T's copy constructor throws.
+ //! <b>Throws</b>: Nothing.
//!
- //! <b>Complexity</b>: Linear to the difference between size() and new_size.
- void resize(size_type new_size)
+ //! <b>Complexity</b>: Constant time.
+ void pop_back() BOOST_CONTAINER_NOEXCEPT
{
- const size_type len = size();
- if (new_size < len)
- this->priv_erase_last_n(len - new_size);
- else{
- size_type n = new_size - this->size();
- container_detail::default_construct_aux_proxy<A, iterator> proxy(this->alloc(), n);
- priv_insert_back_aux_impl(n, proxy);
+ if (this->members_.m_finish.m_cur != this->members_.m_finish.m_first) {
+ --this->members_.m_finish.m_cur;
+ allocator_traits_type::destroy
+ ( this->alloc()
+ , container_detail::to_raw_pointer(this->members_.m_finish.m_cur)
+ );
}
+ else
+ this->priv_pop_back_aux();
}
- //! <b>Effects</b>: Erases the element at position pos.
+ //! <b>Effects</b>: Erases the element at p.
//!
//! <b>Throws</b>: Nothing.
//!
@@ -1377,15 +1514,15 @@ class deque : protected deque_base<T, A>
//! Constant if pos is the first or the last element.
iterator erase(const_iterator pos) BOOST_CONTAINER_NOEXCEPT
{
- const_iterator next = pos;
+ iterator next = pos.unconst();
++next;
- difference_type index = pos - this->members_.m_start;
- if (size_type(index) < (this->size() >> 1)) {
- boost::move_backward(begin(), iterator(pos), iterator(next));
+ size_type index = pos - this->members_.m_start;
+ if (index < (this->size()/2)) {
+ boost::move_backward(this->begin(), pos.unconst(), next);
pop_front();
}
else {
- boost::move(iterator(next), end(), iterator(pos));
+ boost::move(next, this->end(), pos.unconst());
pop_back();
}
return this->members_.m_start + index;
@@ -1406,10 +1543,10 @@ class deque : protected deque_base<T, A>
return this->members_.m_finish;
}
else {
- difference_type n = last - first;
- difference_type elems_before = first - this->members_.m_start;
- if (elems_before < static_cast<difference_type>(this->size() - n) - elems_before) {
- boost::move_backward(begin(), iterator(first), iterator(last));
+ const size_type n = static_cast<size_type>(last - first);
+ const size_type elems_before = static_cast<size_type>(first - this->members_.m_start);
+ if (elems_before < (this->size() - n) - elems_before) {
+ boost::move_backward(begin(), first.unconst(), last.unconst());
iterator new_start = this->members_.m_start + n;
if(!Base::traits_t::trivial_dctr_after_move)
this->priv_destroy_range(this->members_.m_start, new_start);
@@ -1417,7 +1554,7 @@ class deque : protected deque_base<T, A>
this->members_.m_start = new_start;
}
else {
- boost::move(iterator(last), end(), iterator(first));
+ boost::move(last.unconst(), end(), first.unconst());
iterator new_finish = this->members_.m_finish - n;
if(!Base::traits_t::trivial_dctr_after_move)
this->priv_destroy_range(new_finish, this->members_.m_finish);
@@ -1428,18 +1565,17 @@ class deque : protected deque_base<T, A>
}
}
- void priv_erase_last_n(size_type n)
+ //! <b>Effects</b>: Swaps the contents of *this and x.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ void swap(deque &x)
{
- if(n == this->size()) {
- this->clear();
- }
- else {
- iterator new_finish = this->members_.m_finish - n;
- if(!Base::traits_t::trivial_dctr_after_move)
- this->priv_destroy_range(new_finish, this->members_.m_finish);
- this->priv_destroy_nodes(new_finish.m_node + 1, this->members_.m_finish.m_node + 1);
- this->members_.m_finish = new_finish;
- }
+ this->swap_members(x);
+ container_detail::bool_<allocator_traits_type::propagate_on_container_swap::value> flag;
+ container_detail::swap_alloc(this->alloc(), x.alloc(), flag);
+ container_detail::swap_alloc(this->ptr_alloc(), x.ptr_alloc(), flag);
}
//! <b>Effects</b>: Erases all the elements of the deque.
@@ -1467,108 +1603,113 @@ class deque : protected deque_base<T, A>
this->members_.m_finish = this->members_.m_start;
}
- //! <b>Effects</b>: Tries to deallocate the excess of memory created
- //! with previous allocations. The size of the deque is unchanged
+ //! <b>Effects</b>: Returns true if x and y are equal
//!
- //! <b>Throws</b>: If memory allocation throws.
+ //! <b>Complexity</b>: Linear to the number of elements in the container.
+ friend bool operator==(const deque& x, const deque& y)
+ { return x.size() == y.size() && std::equal(x.begin(), x.end(), y.begin()); }
+
+ //! <b>Effects</b>: Returns true if x and y are unequal
+ //!
+ //! <b>Complexity</b>: Linear to the number of elements in the container.
+ friend bool operator!=(const deque& x, const deque& y)
+ { return !(x == y); }
+
+ //! <b>Effects</b>: Returns true if x is less than y
+ //!
+ //! <b>Complexity</b>: Linear to the number of elements in the container.
+ friend bool operator<(const deque& x, const deque& y)
+ { return std::lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); }
+
+ //! <b>Effects</b>: Returns true if x is greater than y
+ //!
+ //! <b>Complexity</b>: Linear to the number of elements in the container.
+ friend bool operator>(const deque& x, const deque& y)
+ { return y < x; }
+
+ //! <b>Effects</b>: Returns true if x is equal or less than y
+ //!
+ //! <b>Complexity</b>: Linear to the number of elements in the container.
+ friend bool operator<=(const deque& x, const deque& y)
+ { return !(y < x); }
+
+ //! <b>Effects</b>: Returns true if x is equal or greater than y
+ //!
+ //! <b>Complexity</b>: Linear to the number of elements in the container.
+ friend bool operator>=(const deque& x, const deque& y)
+ { return !(x < y); }
+
+ //! <b>Effects</b>: x.swap(y)
//!
//! <b>Complexity</b>: Constant.
- void shrink_to_fit()
- {
- //This deque implementation already
- //deallocates excess nodes when erasing
- //so there is nothing to do except for
- //empty deque
- if(this->empty()){
- this->priv_clear_map();
- }
- }
+ friend void swap(deque& x, deque& y)
+ { x.swap(y); }
- /// @cond
+ #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
private:
- void priv_range_check(size_type n) const
- { if (n >= this->size()) BOOST_RETHROW std::out_of_range("deque"); }
- iterator priv_insert(const_iterator position, const value_type &x)
+ void priv_erase_last_n(size_type n)
{
- if (position == cbegin()){
- this->push_front(x);
- return begin();
- }
- else if (position == cend()){
- this->push_back(x);
- return (end()-1);
+ if(n == this->size()) {
+ this->clear();
}
else {
- size_type n = position - cbegin();
- this->priv_insert_aux(position, size_type(1), x);
- return iterator(this->begin() + n);
+ iterator new_finish = this->members_.m_finish - n;
+ if(!Base::traits_t::trivial_dctr_after_move)
+ this->priv_destroy_range(new_finish, this->members_.m_finish);
+ this->priv_destroy_nodes(new_finish.m_node + 1, this->members_.m_finish.m_node + 1);
+ this->members_.m_finish = new_finish;
}
}
- iterator priv_insert(const_iterator position, BOOST_RV_REF(value_type) mx)
+ void priv_range_check(size_type n) const
+ { if (n >= this->size()) throw_out_of_range("deque::at out of range"); }
+
+ template <class U>
+ iterator priv_insert(const_iterator p, BOOST_FWD_REF(U) x)
{
- if (position == cbegin()) {
- this->push_front(boost::move(mx));
+ if (p == cbegin()){
+ this->push_front(::boost::forward<U>(x));
return begin();
}
- else if (position == cend()) {
- this->push_back(boost::move(mx));
- return(end()-1);
+ else if (p == cend()){
+ this->push_back(::boost::forward<U>(x));
+ return --end();
}
else {
- //Just call more general insert(pos, size, value) and return iterator
- size_type n = position - begin();
- this->priv_insert_aux(position, move_it(r_iterator(mx, 1)), move_it(r_iterator()));
- return iterator(this->begin() + n);
- }
- }
-
- void priv_push_front(const value_type &t)
- {
- if(this->priv_push_front_simple_available()){
- allocator_traits_type::construct
- ( this->alloc(), this->priv_push_front_simple_pos(), t);
- this->priv_push_front_simple_commit();
- }
- else{
- this->priv_insert_aux(cbegin(), size_type(1), t);
+ return priv_insert_aux_impl
+ ( p, (size_type)1
+ , container_detail::get_insert_value_proxy<iterator, Allocator>(::boost::forward<U>(x)));
}
}
- void priv_push_front(BOOST_RV_REF(value_type) t)
+ template <class U>
+ void priv_push_front(BOOST_FWD_REF(U) x)
{
if(this->priv_push_front_simple_available()){
allocator_traits_type::construct
- ( this->alloc(), this->priv_push_front_simple_pos(), boost::move(t));
+ ( this->alloc(), this->priv_push_front_simple_pos(), ::boost::forward<U>(x));
this->priv_push_front_simple_commit();
}
else{
- this->priv_insert_aux(cbegin(), move_it(r_iterator(t, 1)), move_it(r_iterator()));
+ priv_insert_aux_impl
+ ( this->cbegin(), (size_type)1
+ , container_detail::get_insert_value_proxy<iterator, Allocator>(::boost::forward<U>(x)));
}
}
- void priv_push_back(const value_type &t)
+ template <class U>
+ void priv_push_back(BOOST_FWD_REF(U) x)
{
if(this->priv_push_back_simple_available()){
allocator_traits_type::construct
- ( this->alloc(), this->priv_push_back_simple_pos(), t);
+ ( this->alloc(), this->priv_push_back_simple_pos(), ::boost::forward<U>(x));
this->priv_push_back_simple_commit();
}
else{
- this->priv_insert_aux(cend(), size_type(1), t);
- }
- }
-
- void priv_push_back(BOOST_RV_REF(T) t)
- {
- if(this->priv_push_back_simple_available()){
- allocator_traits_type::construct
- ( this->alloc(), this->priv_push_back_simple_pos(), boost::move(t));
- this->priv_push_back_simple_commit();
- }
- else{
- this->priv_insert_aux(cend(), move_it(r_iterator(t, 1)), move_it(r_iterator()));
+ priv_insert_aux_impl
+ ( this->cend(), (size_type)1
+ , container_detail::get_insert_value_proxy<iterator, Allocator>(::boost::forward<U>(x)));
}
}
@@ -1600,54 +1741,12 @@ class deque : protected deque_base<T, A>
void priv_push_front_simple_commit()
{ --this->members_.m_start.m_cur; }
- template <class InpIt>
- void priv_insert_aux(const_iterator pos, InpIt first, InpIt last, std::input_iterator_tag)
- {
- for(;first != last; ++first){
- this->insert(pos, boost::move(value_type(*first)));
- }
- }
-
- template <class FwdIt>
- void priv_insert_aux(const_iterator pos, FwdIt first, FwdIt last, std::forward_iterator_tag)
- { this->priv_insert_aux(pos, first, last); }
-
- // assign(), a generalized assignment member function. Two
- // versions: one that takes a count, and one that takes a range.
- // The range version is a member template, so we dispatch on whether
- // or not the type is an integer.
- void priv_fill_assign(size_type n, const T& val)
- {
- if (n > size()) {
- std::fill(begin(), end(), val);
- this->insert(cend(), n - size(), val);
- }
- else {
- this->erase(cbegin() + n, cend());
- std::fill(begin(), end(), val);
- }
- }
-
- template <class Integer>
- void priv_initialize_dispatch(Integer n, Integer x, container_detail::true_)
- {
- this->priv_initialize_map(n);
- this->priv_fill_initialize(x);
- }
-
- template <class InpIt>
- void priv_initialize_dispatch(InpIt first, InpIt last, container_detail::false_)
- {
- typedef typename std::iterator_traits<InpIt>::iterator_category ItCat;
- this->priv_range_initialize(first, last, ItCat());
- }
-
void priv_destroy_range(iterator p, iterator p2)
{
for(;p != p2; ++p){
allocator_traits_type::destroy
( this->alloc()
- , container_detail::to_raw_pointer(&*p)
+ , container_detail::to_raw_pointer(container_detail::iterator_to_pointer(p))
);
}
}
@@ -1657,132 +1756,92 @@ class deque : protected deque_base<T, A>
for(;p != p2; ++p){
allocator_traits_type::destroy
( this->alloc()
- , container_detail::to_raw_pointer(&*p)
+ , container_detail::to_raw_pointer(container_detail::iterator_to_pointer(p))
);
}
}
- template <class Integer>
- void priv_assign_dispatch(Integer n, Integer val, container_detail::true_)
- { this->priv_fill_assign((size_type) n, (value_type)val); }
-
- template <class InpIt>
- void priv_assign_dispatch(InpIt first, InpIt last, container_detail::false_)
- {
- typedef typename std::iterator_traits<InpIt>::iterator_category ItCat;
- this->priv_assign_aux(first, last, ItCat());
- }
-
- template <class InpIt>
- void priv_assign_aux(InpIt first, InpIt last, std::input_iterator_tag)
- {
- iterator cur = begin();
- for ( ; first != last && cur != end(); ++cur, ++first)
- *cur = *first;
- if (first == last)
- this->erase(cur, cend());
- else
- this->insert(cend(), first, last);
- }
-
- template <class FwdIt>
- void priv_assign_aux(FwdIt first, FwdIt last, std::forward_iterator_tag)
- {
- size_type len = std::distance(first, last);
- if (len > size()) {
- FwdIt mid = first;
- std::advance(mid, size());
- boost::copy_or_move(first, mid, begin());
- this->insert(cend(), mid, last);
- }
- else
- this->erase(boost::copy_or_move(first, last, begin()), cend());
- }
-
- template <class Integer>
- void priv_insert_dispatch(const_iterator pos, Integer n, Integer x, container_detail::true_)
- { this->priv_fill_insert(pos, (size_type) n, (value_type)x); }
-
- template <class InpIt>
- void priv_insert_dispatch(const_iterator pos,InpIt first, InpIt last, container_detail::false_)
+ template<class InsertProxy>
+ iterator priv_insert_aux_impl(const_iterator p, size_type n, InsertProxy proxy)
{
- typedef typename std::iterator_traits<InpIt>::iterator_category ItCat;
- this->priv_insert_aux(pos, first, last, ItCat());
- }
-
- void priv_insert_aux(const_iterator pos, size_type n, const value_type& x)
- {
- typedef constant_iterator<value_type, difference_type> c_it;
- this->priv_insert_aux(pos, c_it(x, n), c_it());
- }
-
- //Just forward all operations to priv_insert_aux_impl
- template <class FwdIt>
- void priv_insert_aux(const_iterator p, FwdIt first, FwdIt last)
- {
- container_detail::advanced_insert_aux_proxy<A, FwdIt, iterator> proxy(this->alloc(), first, last);
- priv_insert_aux_impl(p, (size_type)std::distance(first, last), proxy);
- }
-
- void priv_insert_aux_impl(const_iterator p, size_type n, advanced_insert_aux_int_t &interf)
- {
- iterator pos(p);
+ iterator pos(p.unconst());
+ const size_type pos_n = p - this->cbegin();
if(!this->members_.m_map){
this->priv_initialize_map(0);
pos = this->begin();
}
- const difference_type elemsbefore = pos - this->members_.m_start;
- size_type length = this->size();
- if (elemsbefore < static_cast<difference_type>(length / 2)) {
- iterator new_start = this->priv_reserve_elements_at_front(n);
- iterator old_start = this->members_.m_start;
- pos = this->members_.m_start + elemsbefore;
- if (elemsbefore >= difference_type(n)) {
- iterator start_n = this->members_.m_start + difference_type(n);
- ::boost::container::uninitialized_move_alloc
- (this->alloc(), this->members_.m_start, start_n, new_start);
+ const size_type elemsbefore = static_cast<size_type>(pos - this->members_.m_start);
+ const size_type length = this->size();
+ if (elemsbefore < length / 2) {
+ const iterator new_start = this->priv_reserve_elements_at_front(n);
+ const iterator old_start = this->members_.m_start;
+ if(!elemsbefore){
+ proxy.uninitialized_copy_n_and_update(this->alloc(), new_start, n);
this->members_.m_start = new_start;
- boost::move(start_n, pos, old_start);
- interf.copy_remaining_to(pos - difference_type(n));
}
- else {
- difference_type mid_count = (difference_type(n) - elemsbefore);
- iterator mid_start = old_start - mid_count;
- interf.uninitialized_copy_some_and_update(mid_start, mid_count, true);
- this->members_.m_start = mid_start;
- ::boost::container::uninitialized_move_alloc
- (this->alloc(), old_start, pos, new_start);
- this->members_.m_start = new_start;
- interf.copy_remaining_to(old_start);
+ else{
+ pos = this->members_.m_start + elemsbefore;
+ if (elemsbefore >= n) {
+ const iterator start_n = this->members_.m_start + n;
+ ::boost::container::uninitialized_move_alloc
+ (this->alloc(), this->members_.m_start, start_n, new_start);
+ this->members_.m_start = new_start;
+ boost::move(start_n, pos, old_start);
+ proxy.copy_n_and_update(this->alloc(), pos - n, n);
+ }
+ else {
+ const size_type mid_count = n - elemsbefore;
+ const iterator mid_start = old_start - mid_count;
+ proxy.uninitialized_copy_n_and_update(this->alloc(), mid_start, mid_count);
+ this->members_.m_start = mid_start;
+ ::boost::container::uninitialized_move_alloc
+ (this->alloc(), old_start, pos, new_start);
+ this->members_.m_start = new_start;
+ proxy.copy_n_and_update(this->alloc(), old_start, elemsbefore);
+ }
}
}
else {
- iterator new_finish = this->priv_reserve_elements_at_back(n);
- iterator old_finish = this->members_.m_finish;
- const difference_type elemsafter =
- difference_type(length) - elemsbefore;
- pos = this->members_.m_finish - elemsafter;
- if (elemsafter >= difference_type(n)) {
- iterator finish_n = this->members_.m_finish - difference_type(n);
- ::boost::container::uninitialized_move_alloc
- (this->alloc(), finish_n, this->members_.m_finish, this->members_.m_finish);
+ const iterator new_finish = this->priv_reserve_elements_at_back(n);
+ const iterator old_finish = this->members_.m_finish;
+ const size_type elemsafter = length - elemsbefore;
+ if(!elemsafter){
+ proxy.uninitialized_copy_n_and_update(this->alloc(), old_finish, n);
this->members_.m_finish = new_finish;
- boost::move_backward(pos, finish_n, old_finish);
- interf.copy_remaining_to(pos);
}
- else {
- interf.uninitialized_copy_some_and_update(old_finish, elemsafter, false);
- this->members_.m_finish += n-elemsafter;
- ::boost::container::uninitialized_move_alloc
- (this->alloc(), pos, old_finish, this->members_.m_finish);
- this->members_.m_finish = new_finish;
- interf.copy_remaining_to(pos);
+ else{
+ pos = old_finish - elemsafter;
+ if (elemsafter >= n) {
+ iterator finish_n = old_finish - difference_type(n);
+ ::boost::container::uninitialized_move_alloc
+ (this->alloc(), finish_n, old_finish, old_finish);
+ this->members_.m_finish = new_finish;
+ boost::move_backward(pos, finish_n, old_finish);
+ proxy.copy_n_and_update(this->alloc(), pos, n);
+ }
+ else {
+ const size_type raw_gap = n - elemsafter;
+ ::boost::container::uninitialized_move_alloc
+ (this->alloc(), pos, old_finish, old_finish + raw_gap);
+ BOOST_TRY{
+ proxy.copy_n_and_update(this->alloc(), pos, elemsafter);
+ proxy.uninitialized_copy_n_and_update(this->alloc(), old_finish, raw_gap);
+ }
+ BOOST_CATCH(...){
+ this->priv_destroy_range(old_finish, old_finish + elemsafter);
+ BOOST_RETHROW
+ }
+ BOOST_CATCH_END
+ this->members_.m_finish = new_finish;
+ }
}
}
+ return this->begin() + pos_n;
}
- void priv_insert_back_aux_impl(size_type n, advanced_insert_aux_int_t &interf)
+ template <class InsertProxy>
+ iterator priv_insert_back_aux_impl(size_type n, InsertProxy proxy)
{
if(!this->members_.m_map){
this->priv_initialize_map(0);
@@ -1790,26 +1849,28 @@ class deque : protected deque_base<T, A>
iterator new_finish = this->priv_reserve_elements_at_back(n);
iterator old_finish = this->members_.m_finish;
- interf.uninitialized_copy_some_and_update(old_finish, n, true);
+ proxy.uninitialized_copy_n_and_update(this->alloc(), old_finish, n);
this->members_.m_finish = new_finish;
+ return iterator(this->members_.m_finish - n);
}
- void priv_insert_front_aux_impl(size_type n, advanced_insert_aux_int_t &interf)
+ template <class InsertProxy>
+ iterator priv_insert_front_aux_impl(size_type n, InsertProxy proxy)
{
if(!this->members_.m_map){
this->priv_initialize_map(0);
}
iterator new_start = this->priv_reserve_elements_at_front(n);
- interf.uninitialized_copy_some_and_update(new_start, difference_type(n), true);
+ proxy.uninitialized_copy_n_and_update(this->alloc(), new_start, n);
this->members_.m_start = new_start;
+ return new_start;
}
-
- void priv_fill_insert(const_iterator pos, size_type n, const value_type& x)
+ iterator priv_fill_insert(const_iterator pos, size_type n, const value_type& x)
{
typedef constant_iterator<value_type, difference_type> c_it;
- this->insert(pos, c_it(x, n), c_it());
+ return this->insert(pos, c_it(x, n), c_it());
}
// Precondition: this->members_.m_start and this->members_.m_finish have already been initialized,
@@ -1832,13 +1893,13 @@ class deque : protected deque_base<T, A>
BOOST_CATCH_END
}
- template <class InpIt>
- void priv_range_initialize(InpIt first, InpIt last, std::input_iterator_tag)
+ template <class InIt>
+ void priv_range_initialize(InIt first, InIt last, std::input_iterator_tag)
{
this->priv_initialize_map(0);
BOOST_TRY {
for ( ; first != last; ++first)
- this->push_back(*first);
+ this->emplace_back(*first);
}
BOOST_CATCH(...){
this->clear();
@@ -1861,12 +1922,10 @@ class deque : protected deque_base<T, A>
++cur_node) {
FwdIt mid = first;
std::advance(mid, this->s_buffer_size());
- ::boost::container::uninitialized_copy_or_move_alloc
- (this->alloc(), first, mid, *cur_node);
+ ::boost::container::uninitialized_copy_alloc(this->alloc(), first, mid, *cur_node);
first = mid;
}
- ::boost::container::uninitialized_copy_or_move_alloc
- (this->alloc(), first, last, this->members_.m_finish.m_first);
+ ::boost::container::uninitialized_copy_alloc(this->alloc(), first, last, this->members_.m_finish.m_first);
}
BOOST_CATCH(...){
this->priv_destroy_range(this->members_.m_start, iterator(*cur_node, cur_node));
@@ -1876,7 +1935,7 @@ class deque : protected deque_base<T, A>
}
// Called only if this->members_.m_finish.m_cur == this->members_.m_finish.m_first.
- void priv_pop_back_aux()
+ void priv_pop_back_aux() BOOST_CONTAINER_NOEXCEPT
{
this->priv_deallocate_node(this->members_.m_finish.m_first);
this->members_.m_finish.priv_set_node(this->members_.m_finish.m_node - 1);
@@ -1891,7 +1950,7 @@ class deque : protected deque_base<T, A>
// if the deque has at least one element (a precondition for this member
// function), and if this->members_.m_start.m_cur == this->members_.m_start.m_last, then the deque
// must have at least two nodes.
- void priv_pop_front_aux()
+ void priv_pop_front_aux() BOOST_CONTAINER_NOEXCEPT
{
allocator_traits_type::destroy
( this->alloc()
@@ -1900,7 +1959,7 @@ class deque : protected deque_base<T, A>
this->priv_deallocate_node(this->members_.m_start.m_first);
this->members_.m_start.priv_set_node(this->members_.m_start.m_node + 1);
this->members_.m_start.m_cur = this->members_.m_start.m_first;
- }
+ }
iterator priv_reserve_elements_at_front(size_type n)
{
@@ -1920,7 +1979,7 @@ class deque : protected deque_base<T, A>
}
BOOST_CATCH(...) {
for (size_type j = 1; j < i; ++j)
- this->priv_deallocate_node(*(this->members_.m_start.m_node - j));
+ this->priv_deallocate_node(*(this->members_.m_start.m_node - j));
BOOST_RETHROW
}
BOOST_CATCH_END
@@ -1945,7 +2004,7 @@ class deque : protected deque_base<T, A>
}
BOOST_CATCH(...) {
for (size_type j = 1; j < i; ++j)
- this->priv_deallocate_node(*(this->members_.m_finish.m_node + j));
+ this->priv_deallocate_node(*(this->members_.m_finish.m_node + j));
BOOST_RETHROW
}
BOOST_CATCH_END
@@ -1985,66 +2044,25 @@ class deque : protected deque_base<T, A>
this->members_.m_start.priv_set_node(new_nstart);
this->members_.m_finish.priv_set_node(new_nstart + old_num_nodes - 1);
}
- /// @endcond
+ #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
};
-// Nonmember functions.
-template <class T, class A>
-inline bool operator==(const deque<T, A>& x,
- const deque<T, A>& y)
-{
- return x.size() == y.size() && equal(x.begin(), x.end(), y.begin());
-}
-
-template <class T, class A>
-inline bool operator<(const deque<T, A>& x,
- const deque<T, A>& y)
-{
- return lexicographical_compare(x.begin(), x.end(), y.begin(), y.end());
-}
-
-template <class T, class A>
-inline bool operator!=(const deque<T, A>& x,
- const deque<T, A>& y)
- { return !(x == y); }
-
-template <class T, class A>
-inline bool operator>(const deque<T, A>& x,
- const deque<T, A>& y)
- { return y < x; }
-
-template <class T, class A>
-inline bool operator<=(const deque<T, A>& x,
- const deque<T, A>& y)
- { return !(y < x); }
-
-template <class T, class A>
-inline bool operator>=(const deque<T, A>& x,
- const deque<T, A>& y)
- { return !(x < y); }
-
-
-template <class T, class A>
-inline void swap(deque<T, A>& x, deque<T, A>& y)
-{ x.swap(y); }
-
}}
-/// @cond
+#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
namespace boost {
-/*
+
//!has_trivial_destructor_after_move<> == true_type
//!specialization for optimizations
-template <class T, class A>
-struct has_trivial_destructor_after_move<boost::container::deque<T, A> >
-{
- enum { value = has_trivial_destructor<A>::value };
-};
-*/
+template <class T, class Allocator>
+struct has_trivial_destructor_after_move<boost::container::deque<T, Allocator> >
+ : public ::boost::has_trivial_destructor_after_move<Allocator>
+{};
+
}
-/// @endcond
+#endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
#include <boost/container/detail/config_end.hpp>