diff --git a/include/boost/container/deque.hpp b/include/boost/container/deque.hpp
index c7f1aca..52b3b68 100644
--- a/include/boost/container/deque.hpp
+++ b/include/boost/container/deque.hpp
@@ -101,17 +101,17 @@ class deque_base
{
BOOST_COPYABLE_AND_MOVABLE(deque_base)
public:
- typedef allocator_traits 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 allocator_traits 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::type ptr_alloc_t;
- typedef allocator_traits ptr_alloc_traits_type;
+ portable_rebind_alloc::type ptr_alloc_t;
+ typedef allocator_traits 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;
@@ -534,46 +534,35 @@ class deque : protected deque_base
/// @cond
private:
typedef deque_base 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:
- public: // Iterators
- typedef typename Base::iterator iterator;
- typedef typename Base::const_iterator const_iterator;
+ //////////////////////////////////////////////
+ //
+ // types
+ //
+ //////////////////////////////////////////////
- typedef std::reverse_iterator const_reverse_iterator;
- typedef std::reverse_iterator reverse_iterator;
-
- typedef allocator_type stored_allocator_type;
+ typedef T value_type;
+ typedef typename ::boost::container::allocator_traits::pointer pointer;
+ typedef typename ::boost::container::allocator_traits::const_pointer const_pointer;
+ typedef typename ::boost::container::allocator_traits::reference reference;
+ typedef typename ::boost::container::allocator_traits::const_reference const_reference;
+ typedef typename ::boost::container::allocator_traits::size_type size_type;
+ typedef typename ::boost::container::allocator_traits::difference_type difference_type;
+ typedef A 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(std::reverse_iterator) reverse_iterator;
+ typedef BOOST_CONTAINER_IMPDEF(std::reverse_iterator) const_reverse_iterator;
/// @cond
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 advanced_insert_aux_int_t;
@@ -584,248 +573,11 @@ class deque : protected deque_base
/// @endcond
public:
-
- //! Effects: Returns a copy of the internal allocator.
- //!
- //! Throws: If allocator's copy constructor throws.
- //!
- //! Complexity: Constant.
- allocator_type get_allocator() const BOOST_CONTAINER_NOEXCEPT
- { return Base::alloc(); }
-
- //! Effects: Returns a reference to the internal allocator.
- //!
- //! Throws: Nothing
- //!
- //! Complexity: Constant.
- //!
- //! Note: Non-standard extension.
- const stored_allocator_type &get_stored_allocator() const BOOST_CONTAINER_NOEXCEPT
- { return Base::alloc(); }
-
- //! Effects: Returns a reference to the internal allocator.
- //!
- //! Throws: Nothing
- //!
- //! Complexity: Constant.
- //!
- //! Note: Non-standard extension.
- stored_allocator_type &get_stored_allocator() BOOST_CONTAINER_NOEXCEPT
- { return Base::alloc(); }
-
- //! Effects: Returns an iterator to the first element contained in the deque.
- //!
- //! Throws: Nothing.
- //!
- //! Complexity: Constant.
- iterator begin() BOOST_CONTAINER_NOEXCEPT
- { return this->members_.m_start; }
-
- //! Effects: Returns an iterator to the end of the deque.
- //!
- //! Throws: Nothing.
- //!
- //! Complexity: Constant.
- iterator end() BOOST_CONTAINER_NOEXCEPT
- { return this->members_.m_finish; }
-
- //! Effects: Returns a const_iterator to the first element contained in the deque.
- //!
- //! Throws: Nothing.
- //!
- //! Complexity: Constant.
- const_iterator begin() const BOOST_CONTAINER_NOEXCEPT
- { return this->members_.m_start; }
-
- //! Effects: Returns a const_iterator to the end of the deque.
- //!
- //! Throws: Nothing.
- //!
- //! Complexity: Constant.
- const_iterator end() const BOOST_CONTAINER_NOEXCEPT
- { return this->members_.m_finish; }
-
- //! Effects: Returns a reverse_iterator pointing to the beginning
- //! of the reversed deque.
- //!
- //! Throws: Nothing.
- //!
- //! Complexity: Constant.
- reverse_iterator rbegin() BOOST_CONTAINER_NOEXCEPT
- { return reverse_iterator(this->members_.m_finish); }
-
- //! Effects: Returns a reverse_iterator pointing to the end
- //! of the reversed deque.
- //!
- //! Throws: Nothing.
- //!
- //! Complexity: Constant.
- reverse_iterator rend() BOOST_CONTAINER_NOEXCEPT
- { return reverse_iterator(this->members_.m_start); }
-
- //! Effects: Returns a const_reverse_iterator pointing to the beginning
- //! of the reversed deque.
- //!
- //! Throws: Nothing.
- //!
- //! Complexity: Constant.
- const_reverse_iterator rbegin() const BOOST_CONTAINER_NOEXCEPT
- { return const_reverse_iterator(this->members_.m_finish); }
-
- //! Effects: Returns a const_reverse_iterator pointing to the end
- //! of the reversed deque.
- //!
- //! Throws: Nothing.
- //!
- //! Complexity: Constant.
- const_reverse_iterator rend() const BOOST_CONTAINER_NOEXCEPT
- { return const_reverse_iterator(this->members_.m_start); }
-
- //! Effects: Returns a const_iterator to the first element contained in the deque.
- //!
- //! Throws: Nothing.
- //!
- //! Complexity: Constant.
- const_iterator cbegin() const BOOST_CONTAINER_NOEXCEPT
- { return this->members_.m_start; }
-
- //! Effects: Returns a const_iterator to the end of the deque.
- //!
- //! Throws: Nothing.
- //!
- //! Complexity: Constant.
- const_iterator cend() const BOOST_CONTAINER_NOEXCEPT
- { return this->members_.m_finish; }
-
- //! Effects: Returns a const_reverse_iterator pointing to the beginning
- //! of the reversed deque.
- //!
- //! Throws: Nothing.
- //!
- //! Complexity: Constant.
- const_reverse_iterator crbegin() const BOOST_CONTAINER_NOEXCEPT
- { return const_reverse_iterator(this->members_.m_finish); }
-
- //! Effects: Returns a const_reverse_iterator pointing to the end
- //! of the reversed deque.
- //!
- //! Throws: Nothing.
- //!
- //! Complexity: Constant.
- const_reverse_iterator crend() const BOOST_CONTAINER_NOEXCEPT
- { return const_reverse_iterator(this->members_.m_start); }
-
- //! Requires: size() > n.
- //!
- //! Effects: Returns a reference to the nth element
- //! from the beginning of the container.
- //!
- //! Throws: Nothing.
- //!
- //! Complexity: Constant.
- reference operator[](size_type n) BOOST_CONTAINER_NOEXCEPT
- { return this->members_.m_start[difference_type(n)]; }
-
- //! Requires: size() > n.
- //!
- //! Effects: Returns a const reference to the nth element
- //! from the beginning of the container.
- //!
- //! Throws: Nothing.
- //!
- //! Complexity: Constant.
- const_reference operator[](size_type n) const BOOST_CONTAINER_NOEXCEPT
- { return this->members_.m_start[difference_type(n)]; }
-
- //! Requires: size() > n.
- //!
- //! Effects: Returns a reference to the nth element
- //! from the beginning of the container.
- //!
- //! Throws: std::range_error if n >= size()
- //!
- //! Complexity: Constant.
- reference at(size_type n)
- { this->priv_range_check(n); return (*this)[n]; }
-
- //! Requires: size() > n.
- //!
- //! Effects: Returns a const reference to the nth element
- //! from the beginning of the container.
- //!
- //! Throws: std::range_error if n >= size()
- //!
- //! Complexity: Constant.
- const_reference at(size_type n) const
- { this->priv_range_check(n); return (*this)[n]; }
-
- //! Requires: !empty()
- //!
- //! Effects: Returns a reference to the first
- //! element of the container.
- //!
- //! Throws: Nothing.
- //!
- //! Complexity: Constant.
- reference front() BOOST_CONTAINER_NOEXCEPT
- { return *this->members_.m_start; }
-
- //! Requires: !empty()
- //!
- //! Effects: Returns a const reference to the first element
- //! from the beginning of the container.
- //!
- //! Throws: Nothing.
- //!
- //! Complexity: Constant.
- const_reference front() const BOOST_CONTAINER_NOEXCEPT
- { return *this->members_.m_start; }
-
- //! Requires: !empty()
- //!
- //! Effects: Returns a reference to the last
- //! element of the container.
- //!
- //! Throws: Nothing.
- //!
- //! Complexity: Constant.
- reference back() BOOST_CONTAINER_NOEXCEPT
- { return *(end()-1); }
-
- //! Requires: !empty()
- //!
- //! Effects: Returns a const reference to the last
- //! element of the container.
- //!
- //! Throws: Nothing.
- //!
- //! Complexity: Constant.
- const_reference back() const BOOST_CONTAINER_NOEXCEPT
- { return *(cend()-1); }
-
- //! Effects: Returns the number of the elements contained in the deque.
- //!
- //! Throws: Nothing.
- //!
- //! Complexity: Constant.
- size_type size() const BOOST_CONTAINER_NOEXCEPT
- { return this->members_.m_finish - this->members_.m_start; }
-
- //! Effects: Returns the largest possible size of the deque.
- //!
- //! Throws: Nothing.
- //!
- //! Complexity: Constant.
- size_type max_size() const BOOST_CONTAINER_NOEXCEPT
- { return allocator_traits_type::max_size(this->alloc()); }
-
- //! Effects: Returns true if the deque contains no elements.
- //!
- //! Throws: Nothing.
- //!
- //! Complexity: Constant.
- bool empty() const BOOST_CONTAINER_NOEXCEPT
- { return this->members_.m_finish == this->members_.m_start; }
+ //////////////////////////////////////////////
+ //
+ // construct/copy/destroy
+ //
+ //////////////////////////////////////////////
//! Effects: Default constructors a deque.
//!
@@ -872,6 +624,27 @@ class deque : protected deque_base
: Base(n, a)
{ this->priv_fill_initialize(value); }
+ //! Effects: Constructs a deque that will use a copy of allocator a
+ //! and inserts a copy of the range [first, last) in the deque.
+ //!
+ //! Throws: If allocator_type's default constructor or copy constructor
+ //! throws or T's constructor taking an dereferenced InIt throws.
+ //!
+ //! Complexity: Linear to the range [first, last).
+ template
+ 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::value
+ >::type * = 0
+ #endif
+ )
+ : Base(a)
+ {
+ typedef typename std::iterator_traits::iterator_category ItCat;
+ this->priv_range_initialize(first, last, ItCat());
+ }
+
//! Effects: Copy constructs a deque.
//!
//! Postcondition: x == *this.
@@ -936,27 +709,6 @@ class deque : protected deque_base
}
}
- //! Effects: Constructs a deque that will use a copy of allocator a
- //! and inserts a copy of the range [first, last) in the deque.
- //!
- //! Throws: If allocator_type's default constructor or copy constructor
- //! throws or T's constructor taking an dereferenced InIt throws.
- //!
- //! Complexity: Linear to the range [first, last).
- template
- 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::value
- >::type * = 0
- #endif
- )
- : Base(a)
- {
- typedef typename std::iterator_traits::iterator_category ItCat;
- this->priv_range_initialize(first, last, ItCat());
- }
-
//! Effects: Destroys the deque. All stored values are destroyed
//! and used memory is deallocated.
//!
@@ -1028,19 +780,6 @@ class deque : protected deque_base
return *this;
}
- //! Effects: Swaps the contents of *this and x.
- //!
- //! Throws: Nothing.
- //!
- //! Complexity: Constant.
- void swap(deque &x)
- {
- this->swap_members(x);
- container_detail::bool_ flag;
- container_detail::swap_alloc(this->alloc(), x.alloc(), flag);
- container_detail::swap_alloc(this->ptr_alloc(), x.ptr_alloc(), flag);
- }
-
//! Effects: Assigns the n copies of val to *this.
//!
//! Throws: If memory allocation throws or T's copy constructor throws.
@@ -1068,15 +807,15 @@ class deque : protected deque_base
#endif
)
{
- iterator cur = begin();
+ iterator cur = this->begin();
for ( ; first != last && cur != end(); ++cur, ++first){
*cur = *first;
}
if (first == last){
- this->erase(cur, cend());
+ this->erase(cur, this->cend());
}
else{
- this->insert(cend(), first, last);
+ this->insert(this->cend(), first, last);
}
}
@@ -1092,35 +831,473 @@ class deque : protected deque_base
const size_type len = std::distance(first, last);
if (len > size()) {
FwdIt mid = first;
- std::advance(mid, size());
+ std::advance(mid, this->size());
boost::copy_or_move(first, mid, begin());
- this->insert(cend(), mid, last);
+ this->insert(this->cend(), mid, last);
}
else{
- this->erase(boost::copy_or_move(first, last, begin()), cend());
+ this->erase(boost::copy_or_move(first, last, this->begin()), cend());
}
}
#endif
- #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
- //! Effects: Inserts a copy of x at the end of the deque.
+ //! Effects: Returns a copy of the internal allocator.
//!
- //! Throws: If memory allocation throws or
- //! T's copy constructor throws.
+ //! Throws: If allocator's copy constructor throws.
//!
- //! Complexity: Amortized constant time.
- void push_back(const T &x);
+ //! Complexity: Constant.
+ allocator_type get_allocator() const BOOST_CONTAINER_NOEXCEPT
+ { return Base::alloc(); }
- //! Effects: Constructs a new element in the end of the deque
- //! and moves the resources of mx to this new element.
+ //! Effects: Returns a reference to the internal allocator.
+ //!
+ //! Throws: Nothing
+ //!
+ //! Complexity: Constant.
+ //!
+ //! Note: Non-standard extension.
+ const stored_allocator_type &get_stored_allocator() const BOOST_CONTAINER_NOEXCEPT
+ { return Base::alloc(); }
+
+ //////////////////////////////////////////////
+ //
+ // iterators
+ //
+ //////////////////////////////////////////////
+
+ //! Effects: Returns a reference to the internal allocator.
+ //!
+ //! Throws: Nothing
+ //!
+ //! Complexity: Constant.
+ //!
+ //! Note: Non-standard extension.
+ stored_allocator_type &get_stored_allocator() BOOST_CONTAINER_NOEXCEPT
+ { return Base::alloc(); }
+
+ //! Effects: Returns an iterator to the first element contained in the deque.
+ //!
+ //! Throws: Nothing.
+ //!
+ //! Complexity: Constant.
+ iterator begin() BOOST_CONTAINER_NOEXCEPT
+ { return this->members_.m_start; }
+
+ //! Effects: Returns a const_iterator to the first element contained in the deque.
+ //!
+ //! Throws: Nothing.
+ //!
+ //! Complexity: Constant.
+ const_iterator begin() const BOOST_CONTAINER_NOEXCEPT
+ { return this->members_.m_start; }
+
+ //! Effects: Returns an iterator to the end of the deque.
+ //!
+ //! Throws: Nothing.
+ //!
+ //! Complexity: Constant.
+ iterator end() BOOST_CONTAINER_NOEXCEPT
+ { return this->members_.m_finish; }
+
+ //! Effects: Returns a const_iterator to the end of the deque.
+ //!
+ //! Throws: Nothing.
+ //!
+ //! Complexity: Constant.
+ const_iterator end() const BOOST_CONTAINER_NOEXCEPT
+ { return this->members_.m_finish; }
+
+ //! Effects: Returns a reverse_iterator pointing to the beginning
+ //! of the reversed deque.
+ //!
+ //! Throws: Nothing.
+ //!
+ //! Complexity: Constant.
+ reverse_iterator rbegin() BOOST_CONTAINER_NOEXCEPT
+ { return reverse_iterator(this->members_.m_finish); }
+
+ //! Effects: Returns a const_reverse_iterator pointing to the beginning
+ //! of the reversed deque.
+ //!
+ //! Throws: Nothing.
+ //!
+ //! Complexity: Constant.
+ const_reverse_iterator rbegin() const BOOST_CONTAINER_NOEXCEPT
+ { return const_reverse_iterator(this->members_.m_finish); }
+
+ //! Effects: Returns a reverse_iterator pointing to the end
+ //! of the reversed deque.
+ //!
+ //! Throws: Nothing.
+ //!
+ //! Complexity: Constant.
+ reverse_iterator rend() BOOST_CONTAINER_NOEXCEPT
+ { return reverse_iterator(this->members_.m_start); }
+
+ //! Effects: Returns a const_reverse_iterator pointing to the end
+ //! of the reversed deque.
+ //!
+ //! Throws: Nothing.
+ //!
+ //! Complexity: Constant.
+ const_reverse_iterator rend() const BOOST_CONTAINER_NOEXCEPT
+ { return const_reverse_iterator(this->members_.m_start); }
+
+ //! Effects: Returns a const_iterator to the first element contained in the deque.
+ //!
+ //! Throws: Nothing.
+ //!
+ //! Complexity: Constant.
+ const_iterator cbegin() const BOOST_CONTAINER_NOEXCEPT
+ { return this->members_.m_start; }
+
+ //! Effects: Returns a const_iterator to the end of the deque.
+ //!
+ //! Throws: Nothing.
+ //!
+ //! Complexity: Constant.
+ const_iterator cend() const BOOST_CONTAINER_NOEXCEPT
+ { return this->members_.m_finish; }
+
+ //! Effects: Returns a const_reverse_iterator pointing to the beginning
+ //! of the reversed deque.
+ //!
+ //! Throws: Nothing.
+ //!
+ //! Complexity: Constant.
+ const_reverse_iterator crbegin() const BOOST_CONTAINER_NOEXCEPT
+ { return const_reverse_iterator(this->members_.m_finish); }
+
+ //! Effects: Returns a const_reverse_iterator pointing to the end
+ //! of the reversed deque.
+ //!
+ //! Throws: Nothing.
+ //!
+ //! Complexity: Constant.
+ const_reverse_iterator crend() const BOOST_CONTAINER_NOEXCEPT
+ { return const_reverse_iterator(this->members_.m_start); }
+
+ //////////////////////////////////////////////
+ //
+ // capacity
+ //
+ //////////////////////////////////////////////
+
+ //! Effects: Returns true if the deque contains no elements.
+ //!
+ //! Throws: Nothing.
+ //!
+ //! Complexity: Constant.
+ bool empty() const BOOST_CONTAINER_NOEXCEPT
+ { return this->members_.m_finish == this->members_.m_start; }
+
+ //! Effects: Returns the number of the elements contained in the deque.
+ //!
+ //! Throws: Nothing.
+ //!
+ //! Complexity: Constant.
+ size_type size() const BOOST_CONTAINER_NOEXCEPT
+ { return this->members_.m_finish - this->members_.m_start; }
+
+ //! Effects: Returns the largest possible size of the deque.
+ //!
+ //! Throws: Nothing.
+ //!
+ //! Complexity: Constant.
+ size_type max_size() const BOOST_CONTAINER_NOEXCEPT
+ { return allocator_traits_type::max_size(this->alloc()); }
+
+ //! Effects: Inserts or erases elements at the end such that
+ //! the size becomes n. New elements are default constructed.
+ //!
+ //! Throws: If memory allocation throws, or T's copy constructor throws.
+ //!
+ //! Complexity: Linear to the difference between size() and new_size.
+ void resize(size_type new_size)
+ {
+ 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::default_construct_aux_proxy proxy(this->alloc(), n);
+ priv_insert_back_aux_impl(n, proxy);
+ }
+ }
+
+ //! Effects: Inserts or erases elements at the end such that
+ //! the size becomes n. New elements are copy constructed from x.
+ //!
+ //! Throws: If memory allocation throws, or T's copy constructor throws.
+ //!
+ //! Complexity: 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->insert(this->members_.m_finish, new_size - len, x);
+ }
+
+ //! Effects: Tries to deallocate the excess of memory created
+ //! with previous allocations. The size of the deque is unchanged
//!
//! Throws: If memory allocation throws.
//!
- //! Complexity: Amortized constant time.
- void push_back(T &&x);
- #else
- BOOST_MOVE_CONVERSION_AWARE_CATCH(push_back, T, void, priv_push_back)
- #endif
+ //! Complexity: 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();
+ }
+ }
+
+ //////////////////////////////////////////////
+ //
+ // element access
+ //
+ //////////////////////////////////////////////
+
+ //! Requires: !empty()
+ //!
+ //! Effects: Returns a reference to the first
+ //! element of the container.
+ //!
+ //! Throws: Nothing.
+ //!
+ //! Complexity: Constant.
+ reference front() BOOST_CONTAINER_NOEXCEPT
+ { return *this->members_.m_start; }
+
+ //! Requires: !empty()
+ //!
+ //! Effects: Returns a const reference to the first element
+ //! from the beginning of the container.
+ //!
+ //! Throws: Nothing.
+ //!
+ //! Complexity: Constant.
+ const_reference front() const BOOST_CONTAINER_NOEXCEPT
+ { return *this->members_.m_start; }
+
+ //! Requires: !empty()
+ //!
+ //! Effects: Returns a reference to the last
+ //! element of the container.
+ //!
+ //! Throws: Nothing.
+ //!
+ //! Complexity: Constant.
+ reference back() BOOST_CONTAINER_NOEXCEPT
+ { return *(end()-1); }
+
+ //! Requires: !empty()
+ //!
+ //! Effects: Returns a const reference to the last
+ //! element of the container.
+ //!
+ //! Throws: Nothing.
+ //!
+ //! Complexity: Constant.
+ const_reference back() const BOOST_CONTAINER_NOEXCEPT
+ { return *(cend()-1); }
+
+ //! Requires: size() > n.
+ //!
+ //! Effects: Returns a reference to the nth element
+ //! from the beginning of the container.
+ //!
+ //! Throws: Nothing.
+ //!
+ //! Complexity: Constant.
+ reference operator[](size_type n) BOOST_CONTAINER_NOEXCEPT
+ { return this->members_.m_start[difference_type(n)]; }
+
+ //! Requires: size() > n.
+ //!
+ //! Effects: Returns a const reference to the nth element
+ //! from the beginning of the container.
+ //!
+ //! Throws: Nothing.
+ //!
+ //! Complexity: Constant.
+ const_reference operator[](size_type n) const BOOST_CONTAINER_NOEXCEPT
+ { return this->members_.m_start[difference_type(n)]; }
+
+ //! Requires: size() > n.
+ //!
+ //! Effects: Returns a reference to the nth element
+ //! from the beginning of the container.
+ //!
+ //! Throws: std::range_error if n >= size()
+ //!
+ //! Complexity: Constant.
+ reference at(size_type n)
+ { this->priv_range_check(n); return (*this)[n]; }
+
+ //! Requires: size() > n.
+ //!
+ //! Effects: Returns a const reference to the nth element
+ //! from the beginning of the container.
+ //!
+ //! Throws: std::range_error if n >= size()
+ //!
+ //! Complexity: 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)
+
+ //! Effects: Inserts an object of type T constructed with
+ //! std::forward(args)... in the beginning of the deque.
+ //!
+ //! Throws: If memory allocation throws or the in-place constructor throws.
+ //!
+ //! Complexity: Amortized constant time
+ template
+ void emplace_front(Args&&... args)
+ {
+ if(this->priv_push_front_simple_available()){
+ allocator_traits_type::construct
+ ( this->alloc()
+ , this->priv_push_front_simple_pos()
+ , boost::forward(args)...);
+ this->priv_push_front_simple_commit();
+ }
+ else{
+ typedef container_detail::advanced_insert_aux_non_movable_emplace type;
+ type &&proxy = type(this->alloc(), boost::forward(args)...);
+ this->priv_insert_front_aux_impl(1, proxy);
+ }
+ }
+
+ //! Effects: Inserts an object of type T constructed with
+ //! std::forward(args)... in the end of the deque.
+ //!
+ //! Throws: If memory allocation throws or the in-place constructor throws.
+ //!
+ //! Complexity: Amortized constant time
+ template
+ void emplace_back(Args&&... args)
+ {
+ if(this->priv_push_back_simple_available()){
+ allocator_traits_type::construct
+ ( this->alloc()
+ , this->priv_push_back_simple_pos()
+ , boost::forward(args)...);
+ this->priv_push_back_simple_commit();
+ }
+ else{
+ typedef container_detail::advanced_insert_aux_non_movable_emplace type;
+ type &&proxy = type(this->alloc(), boost::forward(args)...);
+ this->priv_insert_back_aux_impl(1, proxy);
+ }
+ }
+
+ //! Requires: position must be a valid iterator of *this.
+ //!
+ //! Effects: Inserts an object of type T constructed with
+ //! std::forward(args)... before position
+ //!
+ //! Throws: If memory allocation throws or the in-place constructor throws.
+ //!
+ //! Complexity: If position is end(), amortized constant time
+ //! Linear time otherwise.
+ template
+ iterator emplace(const_iterator p, Args&&... args)
+ {
+ if(p == this->cbegin()){
+ this->emplace_front(boost::forward(args)...);
+ return this->begin();
+ }
+ else if(p == this->cend()){
+ this->emplace_back(boost::forward(args)...);
+ return (this->end()-1);
+ }
+ else{
+ typedef container_detail::advanced_insert_aux_emplace type;
+ type &&proxy = type(this->alloc(), boost::forward(args)...);
+ return this->priv_insert_aux_impl(p, 1, proxy);
+ }
+ }
+
+ #else //#ifdef BOOST_CONTAINER_PERFECT_FORWARDING
+
+ //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_front(BOOST_PP_ENUM(n, BOOST_CONTAINER_PP_PARAM_LIST, _)) \
+ { \
+ if(priv_push_front_simple_available()){ \
+ allocator_traits_type::construct \
+ ( this->alloc() \
+ , this->priv_push_front_simple_pos() \
+ BOOST_PP_ENUM_TRAILING(n, BOOST_CONTAINER_PP_PARAM_FORWARD, _)); \
+ priv_push_front_simple_commit(); \
+ } \
+ else{ \
+ container_detail::BOOST_PP_CAT(BOOST_PP_CAT \
+ (advanced_insert_aux_non_movable_emplace, n), arg) \
+ proxy \
+ (this->alloc() BOOST_PP_ENUM_TRAILING(n, BOOST_CONTAINER_PP_PARAM_FORWARD, _)); \
+ priv_insert_front_aux_impl(1, proxy); \
+ } \
+ } \
+ \
+ 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_back_simple_available()){ \
+ allocator_traits_type::construct \
+ ( this->alloc() \
+ , this->priv_push_back_simple_pos() \
+ BOOST_PP_ENUM_TRAILING(n, BOOST_CONTAINER_PP_PARAM_FORWARD, _)); \
+ priv_push_back_simple_commit(); \
+ } \
+ else{ \
+ container_detail::BOOST_PP_CAT(BOOST_PP_CAT( \
+ advanced_insert_aux_non_movable_emplace, n), arg) \
+ proxy \
+ (this->alloc() BOOST_PP_ENUM_TRAILING(n, BOOST_CONTAINER_PP_PARAM_FORWARD, _)); \
+ priv_insert_back_aux_impl(1, proxy); \
+ } \
+ } \
+ \
+ BOOST_PP_EXPR_IF(n, template<) BOOST_PP_ENUM_PARAMS(n, class P) BOOST_PP_EXPR_IF(n, >) \
+ iterator emplace(const_iterator p \
+ BOOST_PP_ENUM_TRAILING(n, BOOST_CONTAINER_PP_PARAM_LIST, _)) \
+ { \
+ if(p == this->cbegin()){ \
+ this->emplace_front(BOOST_PP_ENUM(n, BOOST_CONTAINER_PP_PARAM_FORWARD, _)); \
+ return this->begin(); \
+ } \
+ else if(p == cend()){ \
+ this->emplace_back(BOOST_PP_ENUM(n, BOOST_CONTAINER_PP_PARAM_FORWARD, _)); \
+ return (this->end()-1); \
+ } \
+ else{ \
+ container_detail::BOOST_PP_CAT(BOOST_PP_CAT(advanced_insert_aux_emplace, n), arg) \
+ proxy \
+ (this->alloc() BOOST_PP_ENUM_TRAILING(n, BOOST_CONTAINER_PP_PARAM_FORWARD, _)); \
+ return this->priv_insert_aux_impl(p, 1, proxy); \
+ } \
+ } \
+ //!
+ #define BOOST_PP_LOCAL_LIMITS (0, BOOST_CONTAINER_MAX_CONSTRUCTOR_PARAMETERS)
+ #include BOOST_PP_LOCAL_ITERATE()
+
+ #endif //#ifdef BOOST_CONTAINER_PERFECT_FORWARDING
#if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
//! Effects: Inserts a copy of x at the front of the deque.
@@ -1142,41 +1319,25 @@ class deque : protected deque_base
BOOST_MOVE_CONVERSION_AWARE_CATCH(push_front, T, void, priv_push_front)
#endif
- //! Effects: Removes the last element from the deque.
+ #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
+ //! Effects: Inserts a copy of x at the end of the deque.
//!
- //! Throws: Nothing.
+ //! Throws: If memory allocation throws or
+ //! T's copy constructor throws.
//!
- //! Complexity: Constant time.
- void pop_back() BOOST_CONTAINER_NOEXCEPT
- {
- 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();
- }
+ //! Complexity: Amortized constant time.
+ void push_back(const T &x);
- //! Effects: Removes the first element from the deque.
+ //! Effects: Constructs a new element in the end of the deque
+ //! and moves the resources of mx to this new element.
//!
- //! Throws: Nothing.
+ //! Throws: If memory allocation throws.
//!
- //! Complexity: 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->priv_pop_front_aux();
- }
+ //! Complexity: 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)
@@ -1268,179 +1429,40 @@ class deque : protected deque_base
}
#endif
- #if defined(BOOST_CONTAINER_PERFECT_FORWARDING) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
-
- //! Effects: Inserts an object of type T constructed with
- //! std::forward(args)... in the end of the deque.
+ //! Effects: Removes the first element from the deque.
//!
- //! Throws: If memory allocation throws or the in-place constructor throws.
+ //! Throws: Nothing.
//!
- //! Complexity: Amortized constant time
- template
- void emplace_back(Args&&... args)
+ //! Complexity: Constant time.
+ void pop_front() BOOST_CONTAINER_NOEXCEPT
{
- if(this->priv_push_back_simple_available()){
- allocator_traits_type::construct
+ if (this->members_.m_start.m_cur != this->members_.m_start.m_last - 1) {
+ allocator_traits_type::destroy
( this->alloc()
- , this->priv_push_back_simple_pos()
- , boost::forward(args)...);
- this->priv_push_back_simple_commit();
+ , container_detail::to_raw_pointer(this->members_.m_start.m_cur)
+ );
+ ++this->members_.m_start.m_cur;
}
- else{
- typedef container_detail::advanced_insert_aux_non_movable_emplace type;
- type &&proxy = type(this->alloc(), boost::forward(args)...);
- this->priv_insert_back_aux_impl(1, proxy);
- }
- }
-
- //! Effects: Inserts an object of type T constructed with
- //! std::forward(args)... in the beginning of the deque.
- //!
- //! Throws: If memory allocation throws or the in-place constructor throws.
- //!
- //! Complexity: Amortized constant time
- template
- void emplace_front(Args&&... args)
- {
- if(this->priv_push_front_simple_available()){
- allocator_traits_type::construct
- ( this->alloc()
- , this->priv_push_front_simple_pos()
- , boost::forward(args)...);
- this->priv_push_front_simple_commit();
- }
- else{
- typedef container_detail::advanced_insert_aux_non_movable_emplace type;
- type &&proxy = type(this->alloc(), boost::forward(args)...);
- this->priv_insert_front_aux_impl(1, proxy);
- }
- }
-
- //! Requires: position must be a valid iterator of *this.
- //!
- //! Effects: Inserts an object of type T constructed with
- //! std::forward(args)... before position
- //!
- //! Throws: If memory allocation throws or the in-place constructor throws.
- //!
- //! Complexity: If position is end(), amortized constant time
- //! Linear time otherwise.
- template
- iterator emplace(const_iterator p, Args&&... args)
- {
- if(p == this->cbegin()){
- this->emplace_front(boost::forward(args)...);
- return this->begin();
- }
- else if(p == this->cend()){
- this->emplace_back(boost::forward(args)...);
- return (this->end()-1);
- }
- else{
- typedef container_detail::advanced_insert_aux_emplace type;
- type &&proxy = type(this->alloc(), boost::forward(args)...);
- return this->priv_insert_aux_impl(p, 1, proxy);
- }
- }
-
- #else //#ifdef BOOST_CONTAINER_PERFECT_FORWARDING
-
- //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, _)) \
- { \
- if(priv_push_back_simple_available()){ \
- allocator_traits_type::construct \
- ( this->alloc() \
- , this->priv_push_back_simple_pos() \
- BOOST_PP_ENUM_TRAILING(n, BOOST_CONTAINER_PP_PARAM_FORWARD, _)); \
- priv_push_back_simple_commit(); \
- } \
- else{ \
- container_detail::BOOST_PP_CAT(BOOST_PP_CAT( \
- advanced_insert_aux_non_movable_emplace, n), arg) \
- proxy \
- (this->alloc() BOOST_PP_ENUM_TRAILING(n, BOOST_CONTAINER_PP_PARAM_FORWARD, _)); \
- priv_insert_back_aux_impl(1, proxy); \
- } \
- } \
- \
- 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_front_simple_available()){ \
- allocator_traits_type::construct \
- ( this->alloc() \
- , this->priv_push_front_simple_pos() \
- BOOST_PP_ENUM_TRAILING(n, BOOST_CONTAINER_PP_PARAM_FORWARD, _)); \
- priv_push_front_simple_commit(); \
- } \
- else{ \
- container_detail::BOOST_PP_CAT(BOOST_PP_CAT \
- (advanced_insert_aux_non_movable_emplace, n), arg) \
- proxy \
- (this->alloc() BOOST_PP_ENUM_TRAILING(n, BOOST_CONTAINER_PP_PARAM_FORWARD, _)); \
- priv_insert_front_aux_impl(1, proxy); \
- } \
- } \
- \
- BOOST_PP_EXPR_IF(n, template<) BOOST_PP_ENUM_PARAMS(n, class P) BOOST_PP_EXPR_IF(n, >) \
- iterator emplace(const_iterator p \
- BOOST_PP_ENUM_TRAILING(n, BOOST_CONTAINER_PP_PARAM_LIST, _)) \
- { \
- if(p == this->cbegin()){ \
- this->emplace_front(BOOST_PP_ENUM(n, BOOST_CONTAINER_PP_PARAM_FORWARD, _)); \
- return this->begin(); \
- } \
- else if(p == cend()){ \
- this->emplace_back(BOOST_PP_ENUM(n, BOOST_CONTAINER_PP_PARAM_FORWARD, _)); \
- return (this->end()-1); \
- } \
- else{ \
- container_detail::BOOST_PP_CAT(BOOST_PP_CAT(advanced_insert_aux_emplace, n), arg) \
- proxy \
- (this->alloc() BOOST_PP_ENUM_TRAILING(n, BOOST_CONTAINER_PP_PARAM_FORWARD, _)); \
- return this->priv_insert_aux_impl(p, 1, proxy); \
- } \
- } \
- //!
- #define BOOST_PP_LOCAL_LIMITS (0, BOOST_CONTAINER_MAX_CONSTRUCTOR_PARAMETERS)
- #include BOOST_PP_LOCAL_ITERATE()
-
- #endif //#ifdef BOOST_CONTAINER_PERFECT_FORWARDING
-
- //! Effects: Inserts or erases elements at the end such that
- //! the size becomes n. New elements are copy constructed from x.
- //!
- //! Throws: If memory allocation throws, or T's copy constructor throws.
- //!
- //! Complexity: 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->insert(this->members_.m_finish, new_size - len, x);
+ this->priv_pop_front_aux();
}
- //! Effects: Inserts or erases elements at the end such that
- //! the size becomes n. New elements are default constructed.
+ //! Effects: Removes the last element from the deque.
//!
- //! Throws: If memory allocation throws, or T's copy constructor throws.
+ //! Throws: Nothing.
//!
- //! Complexity: Linear to the difference between size() and new_size.
- void resize(size_type new_size)
+ //! Complexity: 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{
- const size_type n = new_size - this->size();
- container_detail::default_construct_aux_proxy 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();
}
//! Effects: Erases the element at position pos.
@@ -1504,18 +1526,17 @@ class deque : protected deque_base
}
}
- void priv_erase_last_n(size_type n)
+ //! Effects: Swaps the contents of *this and x.
+ //!
+ //! Throws: Nothing.
+ //!
+ //! Complexity: 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_ flag;
+ container_detail::swap_alloc(this->alloc(), x.alloc(), flag);
+ container_detail::swap_alloc(this->ptr_alloc(), x.ptr_alloc(), flag);
}
//! Effects: Erases all the elements of the deque.
@@ -1543,25 +1564,23 @@ class deque : protected deque_base
this->members_.m_finish = this->members_.m_start;
}
- //! Effects: Tries to deallocate the excess of memory created
- //! with previous allocations. The size of the deque is unchanged
- //!
- //! Throws: If memory allocation throws.
- //!
- //! Complexity: Constant.
- void shrink_to_fit()
+ /// @cond
+ private:
+
+ void priv_erase_last_n(size_type n)
{
- //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();
+ 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;
}
}
- /// @cond
- private:
void priv_range_check(size_type n) const
{ if (n >= this->size()) BOOST_RETHROW std::out_of_range("deque"); }
@@ -1960,39 +1979,32 @@ class deque : protected deque_base
// Nonmember functions.
template
-inline bool operator==(const deque& x,
- const deque& y)
+inline bool operator==(const deque& x, const deque& y)
{
return x.size() == y.size() && equal(x.begin(), x.end(), y.begin());
}
template
-inline bool operator<(const deque& x,
- const deque& y)
+inline bool operator<(const deque& x, const deque& y)
{
return lexicographical_compare(x.begin(), x.end(), y.begin(), y.end());
}
template
-inline bool operator!=(const deque& x,
- const deque& y)
+inline bool operator!=(const deque& x, const deque& y)
{ return !(x == y); }
template
-inline bool operator>(const deque& x,
- const deque& y)
+inline bool operator>(const deque& x, const deque& y)
{ return y < x; }
template
-inline bool operator<=(const deque& x,
- const deque& y)
- { return !(y < x); }
-
-template
-inline bool operator>=(const deque& x,
- const deque& y)
+inline bool operator>=(const deque& x, const deque& y)
{ return !(x < y); }
+template
+inline bool operator<=(const deque& x, const deque& y)
+ { return !(y < x); }
template
inline void swap(deque& x, deque& y)