| Name | Size | Mode | Actions |
|---|---|---|---|
| base.hpp | 153271 | 0644 | editdlrm |
| debug.hpp | 6981 | 0644 | editdlrm |
| details.hpp | 16631 | 0644 | editdlrm |
| space_optimized.hpp | 96767 | 0644 | editdlrm |
/usr/include/boost/circular_buffer/space_optimized.hpp (96767B)
T must be a copyable class or must have an noexcept move constructor
and move assignment operator.
*/
template is not passed through to html or pdf. So
is used in code section below. Ugly :-( Ideally want a link to capacity_control, but this would require include details and this would expose all the functions in details. There must be a better way of doing this. */ /*! Capacity controller of the space optimized circular buffer. \see capacity_control in details.hpp.
class capacity_control
{
size_type m_capacity; // Available capacity.
size_type m_min_capacity; // Minimum capacity.
public:
capacity_control(size_type capacity, size_type min_capacity = 0)
: m_capacity(capacity), m_min_capacity(min_capacity)
{};
size_type %capacity() const { return m_capacity; }
size_type min_capacity() const { return m_min_capacity; }
operator size_type() const { return m_capacity; }
};
Always
capacity >= min_capacity.The
capacity()represents the capacity of thecircular_buffer_space_optimizedand themin_capacity()determines the minimal allocated size of its internal buffer.The converting constructor of the
*/ typedef cb_details::capacity_controlcapacity_controlallows implicit conversion fromsize_type-like types which ensures compatibility of creating an instance of thecircular_buffer_space_optimizedwith other STL containers. On the other hand the operator%size_type()provides implicit conversion to thesize_typewhich allows to treat the capacity of thecircular_buffer_space_optimizedthe same way as in thecircular_buffer.capacity_type; // Inherited using circular_buffer ::get_allocator; using circular_buffer ::begin; using circular_buffer ::end; using circular_buffer ::rbegin; using circular_buffer ::rend; using circular_buffer ::at; using circular_buffer ::front; using circular_buffer ::back; using circular_buffer ::array_one; using circular_buffer ::array_two; using circular_buffer ::linearize; using circular_buffer ::is_linearized; using circular_buffer ::rotate; using circular_buffer ::size; using circular_buffer ::max_size; using circular_buffer ::empty; #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) reference operator [] (size_type n) { return circular_buffer ::operator[](n); } const_reference operator [] (size_type n) const { return circular_buffer ::operator[](n); } #else using circular_buffer ::operator[]; #endif private: // Member variables //! The capacity controller of the space optimized circular buffer. capacity_type m_capacity_ctrl; public: // Overridden //! Is the circular_buffer_space_optimizedfull? /*! \returntrueif the number of elements stored in thecircular_buffer_space_optimizedequals the capacity of thecircular_buffer_space_optimized;falseotherwise. \throws Nothing. \par Exception Safety No-throw. \par Iterator Invalidation Does not invalidate any iterators. \par Complexity Constant (in the size of thecircular_buffer_space_optimized). \saempty()*/ bool full() const BOOST_NOEXCEPT { return m_capacity_ctrl == size(); } /*! \brief Get the maximum number of elements which can be inserted into thecircular_buffer_space_optimizedwithout overwriting any of already stored elements. \returncapacity().%capacity() - size()\throws Nothing. \par Exception Safety No-throw. \par Iterator Invalidation Does not invalidate any iterators. \par Complexity Constant (in the size of thecircular_buffer_space_optimized). \sacapacity(),size(),max_size()*/ size_type reserve() const BOOST_NOEXCEPT { return m_capacity_ctrl - size(); } //! Get the capacity of thecircular_buffer_space_optimized. /*! \return The capacity controller representing the maximum number of elements which can be stored in thecircular_buffer_space_optimizedand the minimal allocated size of the internal buffer. \throws Nothing. \par Exception Safety No-throw. \par Iterator Invalidation Does not invalidate any iterators. \par Complexity Constant (in the size of thecircular_buffer_space_optimized). \sareserve(),size(),max_size(),set_capacity(const capacity_type&)*/ const capacity_type& capacity() const BOOST_NOEXCEPT { return m_capacity_ctrl; } #if defined(BOOST_CB_TEST) // Return the current capacity of the adapted circular buffer. /* \note This method is not intended to be used directly by the user. It is defined only for testing purposes. */ size_type internal_capacity() const BOOST_NOEXCEPT { return circular_buffer::capacity(); } #endif // #if defined(BOOST_CB_TEST) /*! \brief Change the capacity (and the minimal guaranteed amount of allocated memory) of the circular_buffer_space_optimized. \postcapacity() == capacity_ctrl \&\& size() \<= capacity_ctrl.capacity()
If the current number of elements stored in thecircular_buffer_space_optimizedis greater than the desired new capacity then number of[size() - capacity_ctrl.capacity()]last elements will be removed and the new size will be equal tocapacity_ctrl.capacity().
If the current number of elements stored in thecircular_buffer_space_optimizedis lower than the new capacity then the amount of allocated memory in the internal buffer may be accommodated as necessary but it will never drop belowcapacity_ctrl.min_capacity(). \param capacity_ctrl The new capacity controller. \throws "An allocation error" if memory is exhausted, (std::bad_allocif the standard allocator is used). WhateverT::T(const T&)throws or nothing ifT::T(T&&)is noexcept. \par Exception Safety Strong. \par Iterator Invalidation Invalidates all iterators pointing to thecircular_buffer_space_optimized(except iterators equal toend()). \par Complexity Linear (inmin[size(), capacity_ctrl.%capacity()]). \note To explicitly clear the extra allocated memory use the shrink-to-fit technique:
%boost::%circular_buffer_space_optimized\cb(1000);
...
%boost::%circular_buffer_space_optimized\(cb).swap(cb);
For more information about the shrink-to-fit technique in STL see http://www.gotw.ca/gotw/054.htm. \sarset_capacity(const capacity_type&),\link resize() resize(size_type, const_reference)\endlink*/ void set_capacity(const capacity_type& capacity_ctrl) { m_capacity_ctrl = capacity_ctrl; if (capacity_ctrl < size()) { iterator e = end(); circular_buffer::erase(e - (size() - capacity_ctrl), e); } adjust_min_capacity(); } //! Change the size of the circular_buffer_space_optimized. /*! \postsize() == new_size \&\& capacity().%capacity() >= new_size
If the new size is greater than the current size, copies ofitemwill be inserted at the back of the of thecircular_buffer_space_optimizedin order to achieve the desired size. In the case the resulting size exceeds the current capacity the capacity will be set tonew_size.
If the current number of elements stored in thecircular_buffer_space_optimizedis greater than the desired new size then number of[size() - new_size]last elements will be removed. (The capacity will remain unchanged.)
The amount of allocated memory in the internal buffer may be accommodated as necessary. \param new_size The new size. \param item The element thecircular_buffer_space_optimizedwill be filled with in order to gain the requested size. (See the Effect.) \throws "An allocation error" if memory is exhausted (std::bad_allocif the standard allocator is used). WhateverT::T(const T&)throws. \par Exception Safety Basic. \par Iterator Invalidation Invalidates all iterators pointing to thecircular_buffer_space_optimized(except iterators equal toend()). \par Complexity Linear (in the new size of thecircular_buffer_space_optimized). \sa\link rresize() rresize(size_type, const_reference)\endlink,set_capacity(const capacity_type&)*/ void resize(size_type new_size, param_value_type item = value_type()) { if (new_size > size()) { if (new_size > m_capacity_ctrl) m_capacity_ctrl = capacity_type(new_size, m_capacity_ctrl.min_capacity()); insert(end(), new_size - size(), item); } else { iterator e = end(); erase(e - (size() - new_size), e); } } /*! \brief Change the capacity (and the minimal guaranteed amount of allocated memory) of thecircular_buffer_space_optimized. \postcapacity() == capacity_ctrl \&\& size() \<= capacity_ctrl
If the current number of elements stored in thecircular_buffer_space_optimizedis greater than the desired new capacity then number of[size() - capacity_ctrl.capacity()]first elements will be removed and the new size will be equal tocapacity_ctrl.capacity().
If the current number of elements stored in thecircular_buffer_space_optimizedis lower than the new capacity then the amount of allocated memory in the internal buffer may be accommodated as necessary but it will never drop belowcapacity_ctrl.min_capacity(). \param capacity_ctrl The new capacity controller. \throws "An allocation error" if memory is exhausted (std::bad_allocif the standard allocator is used). WhateverT::T(const T&)throws or nothing ifT::T(T&&)is noexcept. \par Exception Safety Strong. \par Iterator Invalidation Invalidates all iterators pointing to thecircular_buffer_space_optimized(except iterators equal toend()). \par Complexity Linear (inmin[size(), capacity_ctrl.%capacity()]). \saset_capacity(const capacity_type&),\link rresize() rresize(size_type, const_reference)\endlink*/ void rset_capacity(const capacity_type& capacity_ctrl) { m_capacity_ctrl = capacity_ctrl; if (capacity_ctrl < size()) { iterator b = begin(); circular_buffer::rerase(b, b + (size() - capacity_ctrl)); } adjust_min_capacity(); } //! Change the size of the circular_buffer_space_optimized. /*! \postsize() == new_size \&\& capacity().%capacity() >= new_size
If the new size is greater than the current size, copies ofitemwill be inserted at the front of the of thecircular_buffer_space_optimizedin order to achieve the desired size. In the case the resulting size exceeds the current capacity the capacity will be set tonew_size.
If the current number of elements stored in thecircular_buffer_space_optimizedis greater than the desired new size then number of[size() - new_size]first elements will be removed. (The capacity will remain unchanged.)
The amount of allocated memory in the internal buffer may be accommodated as necessary. \param new_size The new size. \param item The element thecircular_buffer_space_optimizedwill be filled with in order to gain the requested size. (See the Effect.) \throws "An allocation error" if memory is exhausted (std::bad_allocif the standard allocator is used). WhateverT::T(const T&)throws. \par Exception Safety Basic. \par Iterator Invalidation Invalidates all iterators pointing to thecircular_buffer_space_optimized(except iterators equal toend()). \par Complexity Linear (in the new size of thecircular_buffer_space_optimized). \sa\link resize() resize(size_type, const_reference)\endlink,rset_capacity(const capacity_type&)*/ void rresize(size_type new_size, param_value_type item = value_type()) { if (new_size > size()) { if (new_size > m_capacity_ctrl) m_capacity_ctrl = capacity_type(new_size, m_capacity_ctrl.min_capacity()); rinsert(begin(), new_size - size(), item); } else { rerase(begin(), end() - new_size); } } //! Create an empty space optimized circular buffer with zero capacity. /*! \postcapacity().%capacity() == 0 \&\& capacity().min_capacity() == 0 \&\& size() == 0\param alloc The allocator. \throws Nothing. \par Complexity Constant. \warning Since Boost version 1.36 the behaviour of this constructor has changed. Now it creates a space optimized circular buffer with zero capacity. */ explicit circular_buffer_space_optimized(const allocator_type& alloc = allocator_type()) BOOST_NOEXCEPT : circular_buffer(0, alloc) , m_capacity_ctrl(0) {} //! Create an empty space optimized circular buffer with the specified capacity. /*! \post capacity() == capacity_ctrl \&\& size() == 0
The amount of allocated memory in the internal buffer iscapacity_ctrl.min_capacity(). \param capacity_ctrl The capacity controller representing the maximum number of elements which can be stored in thecircular_buffer_space_optimizedand the minimal allocated size of the internal buffer. \param alloc The allocator. \throws "An allocation error" if memory is exhausted (std::bad_allocif the standard allocator is used). \par Complexity Constant. */ explicit circular_buffer_space_optimized(capacity_type capacity_ctrl, const allocator_type& alloc = allocator_type()) : circular_buffer(capacity_ctrl.min_capacity(), alloc) , m_capacity_ctrl(capacity_ctrl) {} /*! \brief Create a full space optimized circular buffer with the specified capacity filled with capacity_ctrl.%capacity()copies ofitem. \postcapacity() == capacity_ctrl \&\& full() \&\& (*this)[0] == item \&\& (*this)[1] == item \&\& ... \&\& (*this) [capacity_ctrl.%capacity() - 1] == item
The amount of allocated memory in the internal buffer iscapacity_ctrl.capacity(). \param capacity_ctrl The capacity controller representing the maximum number of elements which can be stored in thecircular_buffer_space_optimizedand the minimal allocated size of the internal buffer. \param item The element the createdcircular_buffer_space_optimizedwill be filled with. \param alloc The allocator. \throws "An allocation error" if memory is exhausted (std::bad_allocif the standard allocator is used). \throws WhateverT::T(const T&)throws. \par Complexity Linear (in thecapacity_ctrl.%capacity()). */ circular_buffer_space_optimized(capacity_type capacity_ctrl, param_value_type item, const allocator_type& alloc = allocator_type()) : circular_buffer(capacity_ctrl.capacity(), item, alloc) , m_capacity_ctrl(capacity_ctrl) {} /*! \brief Create a space optimized circular buffer with the specified capacity filled with ncopies ofitem. \precapacity_ctrl.%capacity() >= n\postcapacity() == capacity_ctrl \&\& size() == n \&\& (*this)[0] == item \&\& (*this)[1] == item \&\& ... \&\& (*this)[n - 1] == item
The amount of allocated memory in the internal buffer ismax[n, capacity_ctrl.min_capacity()]. \param capacity_ctrl The capacity controller representing the maximum number of elements which can be stored in thecircular_buffer_space_optimizedand the minimal allocated size of the internal buffer. \param n The number of elements the createdcircular_buffer_space_optimizedwill be filled with. \param item The element the createdcircular_buffer_space_optimizedwill be filled with. \param alloc The allocator. \throws "An allocation error" if memory is exhausted (std::bad_allocif the standard allocator is used). WhateverT::T(const T&)throws. \par Complexity Linear (in then). */ circular_buffer_space_optimized(capacity_type capacity_ctrl, size_type n, param_value_type item, const allocator_type& alloc = allocator_type()) : circular_buffer(init_capacity(capacity_ctrl, n), n, item, alloc) , m_capacity_ctrl(capacity_ctrl) {} //! The copy constructor. /*! Creates a copy of the specified circular_buffer_space_optimized. \post*this == cb
The amount of allocated memory in the internal buffer iscb.size(). \param cb Thecircular_buffer_space_optimizedto be copied. \throws "An allocation error" if memory is exhausted (std::bad_allocif the standard allocator is used). WhateverT::T(const T&)throws. \par Complexity Linear (in the size ofcb). */ circular_buffer_space_optimized(const circular_buffer_space_optimized& cb) : circular_buffer (cb.begin(), cb.end(), cb.get_allocator()) , m_capacity_ctrl(cb.m_capacity_ctrl) {} #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES //! The move constructor. /*! \brief Move constructs a circular_buffer_space_optimizedfromcb, leavingcbempty. \pre C++ compiler with rvalue references support. \postcb.empty()\param cbcircular_bufferto 'steal' value from. \throws Nothing. \par Constant. */ circular_buffer_space_optimized(circular_buffer_space_optimized&& cb) BOOST_NOEXCEPT : circular_buffer () , m_capacity_ctrl(0) { cb.swap(*this); } #endif // BOOST_NO_CXX11_RVALUE_REFERENCES //! Create a full space optimized circular buffer filled with a copy of the range. /*! \pre Valid range [first, last).
firstandlasthave to meet the requirements of InputIterator. \postcapacity().%capacity() == std::distance(first, last) \&\& capacity().min_capacity() == 0 \&\& full() \&\& (*this)[0]== *first \&\& (*this)[1] == *(first + 1) \&\& ... \&\& (*this)[std::distance(first, last) - 1] == *(last - 1)
The amount of allocated memory in the internal buffer isstd::distance(first, last). \param first The beginning of the range to be copied. \param last The end of the range to be copied. \param alloc The allocator. \throws "An allocation error" if memory is exhausted (std::bad_allocif the standard allocator is used). WhateverT::T(const T&)throws or nothing ifT::T(T&&)is noexcept andInputIteratoris a move iterator. \par Complexity Linear (in thestd::distance(first, last)). */ templatecircular_buffer_space_optimized(InputIterator first, InputIterator last, const allocator_type& alloc = allocator_type()) : circular_buffer (first, last, alloc) , m_capacity_ctrl(circular_buffer ::capacity()) {} /*! \brief Create a space optimized circular buffer with the specified capacity (and the minimal guaranteed amount of allocated memory) filled with a copy of the range. \pre Valid range [first, last).
firstandlasthave to meet the requirements of InputIterator. \postcapacity() == capacity_ctrl \&\& size() \<= std::distance(first, last) \&\& (*this)[0]== *(last - capacity_ctrl.%capacity()) \&\& (*this)[1] == *(last - capacity_ctrl.%capacity() + 1) \&\& ... \&\& (*this)[capacity_ctrl.%capacity() - 1] == *(last - 1)
If the number of items to be copied from the range[first, last)is greater than the specifiedcapacity_ctrl.%capacity()then only elements from the range[last - capacity_ctrl.%capacity(), last)will be copied.
The amount of allocated memory in the internal buffer ismax[capacity_ctrl.min_capacity(), min[capacity_ctrl.%capacity(), std::distance(first, last)]]. \param capacity_ctrl The capacity controller representing the maximum number of elements which can be stored in thecircular_buffer_space_optimizedand the minimal allocated size of the internal buffer. \param first The beginning of the range to be copied. \param last The end of the range to be copied. \param alloc The allocator. \throws "An allocation error" if memory is exhausted (std::bad_allocif the standard allocator is used). WhateverT::T(const T&)throws. \par Complexity Linear (instd::distance(first, last); inmin[capacity_ctrl.%capacity(), std::distance(first, last)]if theInputIteratoris a RandomAccessIterator). */ templatecircular_buffer_space_optimized(capacity_type capacity_ctrl, InputIterator first, InputIterator last, const allocator_type& alloc = allocator_type()) : circular_buffer ( init_capacity(capacity_ctrl, first, last, is_integral ()), first, last, alloc) , m_capacity_ctrl(capacity_ctrl) { reduce_capacity( is_same< BOOST_DEDUCED_TYPENAME std::iterator_traits ::iterator_category, std::input_iterator_tag >()); } #if defined(BOOST_CB_NEVER_DEFINED) // This section will never be compiled - the default destructor will be generated instead. // Declared only for documentation purpose. //! The destructor. /*! Destroys the circular_buffer_space_optimized. \throws Nothing. \par Iterator Invalidation Invalidates all iterators pointing to thecircular_buffer_space_optimized(including iterators equal toend()). \par Complexity Linear (in the size of thecircular_buffer_space_optimized). \saclear()*/ ~circular_buffer_space_optimized(); //! no-comment void erase_begin(size_type n); //! no-comment void erase_end(size_type n); #endif // #if defined(BOOST_CB_NEVER_DEFINED) //! The assign operator. /*! Makes thiscircular_buffer_space_optimizedto become a copy of the specifiedcircular_buffer_space_optimized. \post*this == cb
The amount of allocated memory in the internal buffer iscb.size(). \param cb Thecircular_buffer_space_optimizedto be copied. \throws "An allocation error" if memory is exhausted (std::bad_allocif the standard allocator is used). \throws WhateverT::T(const T&)throws. \par Exception Safety Strong. \par Iterator Invalidation Invalidates all iterators pointing to thiscircular_buffer_space_optimized(except iterators equal toend()). \par Complexity Linear (in the size ofcb). \sa\link assign(size_type, param_value_type) assign(size_type, const_reference)\endlink,\link assign(capacity_type, size_type, param_value_type) assign(capacity_type, size_type, const_reference)\endlink,assign(InputIterator, InputIterator),assign(capacity_type, InputIterator, InputIterator)*/ circular_buffer_space_optimized& operator = (const circular_buffer_space_optimized & cb) { if (this == &cb) return *this; circular_buffer ::assign(cb.begin(), cb.end()); m_capacity_ctrl = cb.m_capacity_ctrl; return *this; } #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES /*! \brief Move assigns content of cbto*this, leavingcbempty. \pre C++ compiler with rvalue references support. \postcb.empty()\param cbcircular_bufferto 'steal' value from. \throws Nothing. \par Complexity Constant. */ circular_buffer_space_optimized& operator = (circular_buffer_space_optimized && cb) BOOST_NOEXCEPT { cb.swap(*this); // now `this` holds `cb` circular_buffer (get_allocator()) // temporary that holds initial `cb` allocator .swap(cb); // makes `cb` empty return *this; } #endif // BOOST_NO_CXX11_RVALUE_REFERENCES //! Assign nitems into the space optimized circular buffer. /*! The content of thecircular_buffer_space_optimizedwill be removed and replaced withncopies of theitem. \postcapacity().%capacity() == n \&\& capacity().min_capacity() == 0 \&\& size() == n \&\& (*this)[0] == item \&\& (*this)[1] == item \&\& ... \&\& (*this) [n - 1] == item
The amount of allocated memory in the internal buffer isn. \param n The number of elements thecircular_buffer_space_optimizedwill be filled with. \param item The element thecircular_buffer_space_optimizedwill be filled with. \throws "An allocation error" if memory is exhausted (std::bad_allocif the standard allocator is used). WhateverT::T(const T&)throws. \par Exception Safety Basic. \par Iterator Invalidation Invalidates all iterators pointing to thecircular_buffer_space_optimized(except iterators equal toend()). \par Complexity Linear (in then). \sa\link operator=(const circular_buffer_space_optimized&) operator=\endlink,\link assign(capacity_type, size_type, param_value_type) assign(capacity_type, size_type, const_reference)\endlink,assign(InputIterator, InputIterator),assign(capacity_type, InputIterator, InputIterator)*/ void assign(size_type n, param_value_type item) { circular_buffer::assign(n, item); m_capacity_ctrl = capacity_type(n); } //! Assign nitems into the space optimized circular buffer specifying the capacity. /*! The capacity of thecircular_buffer_space_optimizedwill be set to the specified value and the content of thecircular_buffer_space_optimizedwill be removed and replaced withncopies of theitem. \precapacity_ctrl.%capacity() >= n\postcapacity() == capacity_ctrl \&\& size() == n \&\& (*this)[0] == item \&\& (*this)[1] == item \&\& ... \&\& (*this) [n - 1] == item
The amount of allocated memory will bemax[n, capacity_ctrl.min_capacity()]. \param capacity_ctrl The new capacity controller. \param n The number of elements thecircular_buffer_space_optimizedwill be filled with. \param item The element thecircular_buffer_space_optimizedwill be filled with. \throws "An allocation error" if memory is exhausted (std::bad_allocif the standard allocator is used). WhateverT::T(const T&)throws. \par Exception Safety Basic. \par Iterator Invalidation Invalidates all iterators pointing to thecircular_buffer_space_optimized(except iterators equal toend()). \par Complexity Linear (in then). \sa\link operator=(const circular_buffer_space_optimized&) operator=\endlink,\link assign(size_type, param_value_type) assign(size_type, const_reference)\endlink,assign(InputIterator, InputIterator),assign(capacity_type, InputIterator, InputIterator)*/ void assign(capacity_type capacity_ctrl, size_type n, param_value_type item) { BOOST_CB_ASSERT(capacity_ctrl.capacity() >= n); // check for new capacity lower than n circular_buffer::assign((std::max)(capacity_ctrl.min_capacity(), n), n, item); m_capacity_ctrl = capacity_ctrl; } //! Assign a copy of the range into the space optimized circular buffer. /*! The content of the circular_buffer_space_optimizedwill be removed and replaced with copies of elements from the specified range. \pre Valid range[first, last).
firstandlasthave to meet the requirements of InputIterator. \postcapacity().%capacity() == std::distance(first, last) \&\& capacity().min_capacity() == 0 \&\& size() == std::distance(first, last) \&\& (*this)[0]== *first \&\& (*this)[1] == *(first + 1) \&\& ... \&\& (*this)[std::distance(first, last) - 1] == *(last - 1)
The amount of allocated memory in the internal buffer isstd::distance(first, last). \param first The beginning of the range to be copied. \param last The end of the range to be copied. \throws "An allocation error" if memory is exhausted (std::bad_allocif the standard allocator is used). WhateverT::T(const T&)throws or nothing ifT::T(T&&)is noexcept andInputIteratoris a move iterator. \par Exception Safety Basic. \par Iterator Invalidation Invalidates all iterators pointing to thecircular_buffer_space_optimized(except iterators equal toend()). \par Complexity Linear (in thestd::distance(first, last)). \sa\link operator=(const circular_buffer_space_optimized&) operator=\endlink,\link assign(size_type, param_value_type) assign(size_type, const_reference)\endlink,\link assign(capacity_type, size_type, param_value_type) assign(capacity_type, size_type, const_reference)\endlink,assign(capacity_type, InputIterator, InputIterator)*/ templatevoid assign(InputIterator first, InputIterator last) { circular_buffer ::assign(first, last); m_capacity_ctrl = capacity_type(circular_buffer ::capacity()); } //! Assign a copy of the range into the space optimized circular buffer specifying the capacity. /*! The capacity of the circular_buffer_space_optimizedwill be set to the specified value and the content of thecircular_buffer_space_optimizedwill be removed and replaced with copies of elements from the specified range. \pre Valid range[first, last).
firstandlasthave to meet the requirements of InputIterator. \postcapacity() == capacity_ctrl \&\& size() \<= std::distance(first, last) \&\& (*this)[0]== *(last - capacity) \&\& (*this)[1] == *(last - capacity + 1) \&\& ... \&\& (*this)[capacity - 1] == *(last - 1)
If the number of items to be copied from the range[first, last)is greater than the specifiedcapacitythen only elements from the range[last - capacity, last)will be copied.
The amount of allocated memory in the internal buffer ismax[std::distance(first, last), capacity_ctrl.min_capacity()]. \param capacity_ctrl The new capacity controller. \param first The beginning of the range to be copied. \param last The end of the range to be copied. \throws "An allocation error" if memory is exhausted (std::bad_allocif the standard allocator is used). WhateverT::T(const T&)throws or nothing ifT::T(T&&)is noexcept andInputIteratoris a move iterator. \par Exception Safety Basic. \par Iterator Invalidation Invalidates all iterators pointing to thecircular_buffer_space_optimized(except iterators equal toend()). \par Complexity Linear (instd::distance(first, last); inmin[capacity_ctrl.%capacity(), std::distance(first, last)]if theInputIteratoris a RandomAccessIterator). \sa\link operator=(const circular_buffer_space_optimized&) operator=\endlink,\link assign(size_type, param_value_type) assign(size_type, const_reference)\endlink,\link assign(capacity_type, size_type, param_value_type) assign(capacity_type, size_type, const_reference)\endlink,assign(InputIterator, InputIterator)*/ templatevoid assign(capacity_type capacity_ctrl, InputIterator first, InputIterator last) { m_capacity_ctrl = capacity_ctrl; circular_buffer ::assign(capacity_ctrl, first, last); } //! Swap the contents of two space-optimized circular-buffers. /*! \post thiscontains elements ofcband vice versa; the capacity and the amount of allocated memory in the internal buffer ofthisequal to the capacity and the amount of allocated memory ofcband vice versa. \param cb Thecircular_buffer_space_optimizedwhose content will be swapped. \throws Nothing. \par Exception Safety No-throw. \par Iterator Invalidation Invalidates all iterators of bothcircular_buffer_space_optimizedcontainers. (On the other hand the iterators still point to the same elements but within another container. If you want to rely on this feature you have to turn the __debug_support off, otherwise an assertion will report an error if such invalidated iterator is used.) \par Complexity Constant (in the size of thecircular_buffer_space_optimized). \saswap(circular_buffer,&, circular_buffer &) swap(circular_buffer_space_optimized*/ // Note link does not work right. Asked on Doxygen forum for advice 23 May 2103. void swap(circular_buffer_space_optimized&, circular_buffer_space_optimized &) & cb) BOOST_NOEXCEPT { std::swap(m_capacity_ctrl, cb.m_capacity_ctrl); circular_buffer ::swap(cb); } //! Insert a new element at the end of the space optimized circular buffer. /*! \post if capacity().%capacity() > 0thenback() == item
If thecircular_buffer_space_optimizedis full, the first element will be removed. If the capacity is0, nothing will be inserted.
The amount of allocated memory in the internal buffer may be predictively increased. \param item The element to be inserted. \throws "An allocation error" if memory is exhausted (std::bad_allocif the standard allocator is used). WhateverT::T(const T&)throws. \par Exception Safety Basic. \par Iterator Invalidation Invalidates all iterators pointing to thecircular_buffer_space_optimized(except iterators equal toend()). \par Complexity Linear (in the size of thecircular_buffer_space_optimized). \sa\link push_front() push_front(const_reference)\endlink,pop_back(),pop_front()*/ void push_back(param_value_type item) { check_low_capacity(); circular_buffer::push_back(item); } //! Insert a new element at the end of the space optimized circular buffer. /*! \post if capacity().%capacity() > 0thenback() == item
If thecircular_buffer_space_optimizedis full, the first element will be removed. If the capacity is0, nothing will be inserted.
The amount of allocated memory in the internal buffer may be predictively increased. \param item The element to be inserted. \throws "An allocation error" if memory is exhausted (std::bad_allocif the standard allocator is used). \par Exception Safety Basic. \par Iterator Invalidation Invalidates all iterators pointing to thecircular_buffer_space_optimized(except iterators equal toend()). \par Complexity Linear (in the size of thecircular_buffer_space_optimized). \sa\link push_front() push_front(const_reference)\endlink,pop_back(),pop_front()*/ void push_back(rvalue_type item) { check_low_capacity(); circular_buffer::push_back(boost::move(item)); } //! Insert a new element at the end of the space optimized circular buffer. /*! \post if capacity().%capacity() > 0thenback() == item
If thecircular_buffer_space_optimizedis full, the first element will be removed. If the capacity is0, nothing will be inserted.
The amount of allocated memory in the internal buffer may be predictively increased. \throws "An allocation error" if memory is exhausted (std::bad_allocif the standard allocator is used). WhateverT::T()throws. WhateverT::T(const T&)throws or nothing ifT::T(T&&)is noexcept. \par Exception Safety Basic. \par Iterator Invalidation Invalidates all iterators pointing to thecircular_buffer_space_optimized(except iterators equal toend()). \par Complexity Linear (in the size of thecircular_buffer_space_optimized). \sa\link push_front() push_front(const_reference)\endlink,pop_back(),pop_front()*/ void push_back() { check_low_capacity(); circular_buffer::push_back(); } //! Insert a new element at the beginning of the space optimized circular buffer. /*! \post if capacity().%capacity() > 0thenfront() == item
If thecircular_buffer_space_optimizedis full, the last element will be removed. If the capacity is0, nothing will be inserted.
The amount of allocated memory in the internal buffer may be predictively increased. \param item The element to be inserted. \throws "An allocation error" if memory is exhausted (std::bad_allocif the standard allocator is used). WhateverT::T(const T&)throws. \par Exception Safety Basic. \par Iterator Invalidation Invalidates all iterators pointing to thecircular_buffer_space_optimized(except iterators equal toend()). \par Complexity Linear (in the size of thecircular_buffer_space_optimized). \sa\link push_back() push_back(const_reference)\endlink,pop_back(),pop_front()*/ void push_front(param_value_type item) { check_low_capacity(); circular_buffer::push_front(item); } //! Insert a new element at the beginning of the space optimized circular buffer. /*! \post if capacity().%capacity() > 0thenfront() == item
If thecircular_buffer_space_optimizedis full, the last element will be removed. If the capacity is0, nothing will be inserted.
The amount of allocated memory in the internal buffer may be predictively increased. \param item The element to be inserted. \throws "An allocation error" if memory is exhausted (std::bad_allocif the standard allocator is used). WhateverT::T(const T&)throws or nothing ifT::T(T&&)is noexcept. \par Exception Safety Basic. \par Iterator Invalidation Invalidates all iterators pointing to thecircular_buffer_space_optimized(except iterators equal toend()). \par Complexity Linear (in the size of thecircular_buffer_space_optimized). \sa\link push_back() push_back(const_reference)\endlink,pop_back(),pop_front()*/ void push_front(rvalue_type item) { check_low_capacity(); circular_buffer::push_front(boost::move(item)); } //! Insert a new element at the beginning of the space optimized circular buffer. /*! \post if capacity().%capacity() > 0thenfront() == item
If thecircular_buffer_space_optimizedis full, the last element will be removed. If the capacity is0, nothing will be inserted.
The amount of allocated memory in the internal buffer may be predictively increased. \throws "An allocation error" if memory is exhausted (std::bad_allocif the standard allocator is used). WhateverT::T()throws. WhateverT::T(const T&)throws or nothing ifT::T(T&&)is noexcept. \par Exception Safety Basic. \par Iterator Invalidation Invalidates all iterators pointing to thecircular_buffer_space_optimized(except iterators equal toend()). \par Complexity Linear (in the size of thecircular_buffer_space_optimized). \sa\link push_back() push_back(const_reference)\endlink,pop_back(),pop_front()*/ void push_front() { check_low_capacity(); circular_buffer::push_front(); } //! Remove the last element from the space optimized circular buffer. /*! \pre !empty()\post The last element is removed from thecircular_buffer_space_optimized.
The amount of allocated memory in the internal buffer may be predictively decreased. \throws "An allocation error" if memory is exhausted (std::bad_allocif the standard allocator is used). \par Exception Safety Basic. \par Iterator Invalidation Invalidates all iterators pointing to thecircular_buffer_space_optimized(except iterators equal toend()). \par Complexity Linear (in the size of thecircular_buffer_space_optimized). \sapop_front(),\link push_back() push_back(const_reference)\endlink,\link push_front() push_front(const_reference)\endlink*/ void pop_back() { circular_buffer::pop_back(); check_high_capacity(); } //! Remove the first element from the space optimized circular buffer. /*! \pre !empty()\post The first element is removed from thecircular_buffer_space_optimized.
The amount of allocated memory in the internal buffer may be predictively decreased. \throws "An allocation error" if memory is exhausted (std::bad_allocif the standard allocator is used). \par Exception Safety Basic. \par Iterator Invalidation Invalidates all iterators pointing to thecircular_buffer_space_optimized(except iterators equal toend()). \par Complexity Linear (in the size of thecircular_buffer_space_optimized). \sapop_back(),\link push_back() push_back(const_reference)\endlink,\link push_front() push_front(const_reference)\endlink*/ void pop_front() { circular_buffer::pop_front(); check_high_capacity(); } //! Insert an element at the specified position. /*! \pre posis a valid iterator pointing to thecircular_buffer_space_optimizedor its end. \post Theitemwill be inserted at the positionpos.
If thecircular_buffer_space_optimizedis full, the first element will be overwritten. If thecircular_buffer_space_optimizedis full and thepospoints tobegin(), then theitemwill not be inserted. If the capacity is0, nothing will be inserted.
The amount of allocated memory in the internal buffer may be predictively increased. \param pos An iterator specifying the position where theitemwill be inserted. \param item The element to be inserted. \return Iterator to the inserted element orbegin()if theitemis not inserted. (See the Effect.) \throws "An allocation error" if memory is exhausted (std::bad_allocif the standard allocator is used). WhateverT::T(const T&)throws. WhateverT::operator = (const T&)throws. \par Exception Safety Basic. \par Iterator Invalidation Invalidates all iterators pointing to thecircular_buffer_space_optimized(except iterators equal toend()). \par Complexity Linear (in the size of thecircular_buffer_space_optimized). \sa\link insert(iterator, size_type, param_value_type) insert(iterator, size_type, value_type)\endlink,insert(iterator, InputIterator, InputIterator),\link rinsert(iterator, param_value_type) rinsert(iterator, value_type)\endlink,\link rinsert(iterator, size_type, param_value_type) rinsert(iterator, size_type, value_type)\endlink,rinsert(iterator, InputIterator, InputIterator)*/ iterator insert(iterator pos, param_value_type item) { size_type index = pos - begin(); check_low_capacity(); return circular_buffer::insert(begin() + index, item); } //! Insert an element at the specified position. /*! \pre posis a valid iterator pointing to thecircular_buffer_space_optimizedor its end. \post Theitemwill be inserted at the positionpos.
If thecircular_buffer_space_optimizedis full, the first element will be overwritten. If thecircular_buffer_space_optimizedis full and thepospoints tobegin(), then theitemwill not be inserted. If the capacity is0, nothing will be inserted.
The amount of allocated memory in the internal buffer may be predictively increased. \param pos An iterator specifying the position where theitemwill be inserted. \param item The element to be inserted. \return Iterator to the inserted element orbegin()if theitemis not inserted. (See the Effect.) \throws "An allocation error" if memory is exhausted (std::bad_allocif the standard allocator is used). WhateverT::T(const T&)throws or nothing ifT::T(T&&)is noexcept. \par Exception Safety Basic. \par Iterator Invalidation Invalidates all iterators pointing to thecircular_buffer_space_optimized(except iterators equal toend()). \par Complexity Linear (in the size of thecircular_buffer_space_optimized). \sa\link insert(iterator, size_type, param_value_type) insert(iterator, size_type, value_type)\endlink,insert(iterator, InputIterator, InputIterator),\link rinsert(iterator, param_value_type) rinsert(iterator, value_type)\endlink,\link rinsert(iterator, size_type, param_value_type) rinsert(iterator, size_type, value_type)\endlink,rinsert(iterator, InputIterator, InputIterator)*/ iterator insert(iterator pos, rvalue_type item) { size_type index = pos - begin(); check_low_capacity(); return circular_buffer::insert(begin() + index, boost::move(item)); } //! Insert an element at the specified position. /*! \pre posis a valid iterator pointing to thecircular_buffer_space_optimizedor its end. \post Theitemwill be inserted at the positionpos.
If thecircular_buffer_space_optimizedis full, the first element will be overwritten. If thecircular_buffer_space_optimizedis full and thepospoints tobegin(), then theitemwill not be inserted. If the capacity is0, nothing will be inserted.
The amount of allocated memory in the internal buffer may be predictively increased. \param pos An iterator specifying the position where theitemwill be inserted. \return Iterator to the inserted element orbegin()if theitemis not inserted. (See the Effect.) \throws "An allocation error" if memory is exhausted (std::bad_allocif the standard allocator is used). WhateverT::T()throws. WhateverT::T(const T&)throws or nothing ifT::T(T&&)is noexcept. \par Exception Safety Basic. \par Iterator Invalidation Invalidates all iterators pointing to thecircular_buffer_space_optimized(except iterators equal toend()). \par Complexity Linear (in the size of thecircular_buffer_space_optimized). \sa\link insert(iterator, size_type, param_value_type) insert(iterator, size_type, value_type)\endlink,insert(iterator, InputIterator, InputIterator),\link rinsert(iterator, param_value_type) rinsert(iterator, value_type)\endlink,\link rinsert(iterator, size_type, param_value_type) rinsert(iterator, size_type, value_type)\endlink,rinsert(iterator, InputIterator, InputIterator)*/ iterator insert(iterator pos) { size_type index = pos - begin(); check_low_capacity(); return circular_buffer::insert(begin() + index); } //! Insert ncopies of theitemat the specified position. /*! \preposis a valid iterator pointing to thecircular_buffer_space_optimizedor its end. \post The number ofmin[n, (pos - begin()) + reserve()]elements will be inserted at the positionpos.
The number ofmin[pos - begin(), max[0, n - reserve()]]elements will be overwritten at the beginning of thecircular_buffer_space_optimized.
(See Example for the explanation.)
The amount of allocated memory in the internal buffer may be predictively increased. \param pos An iterator specifying the position where theitems will be inserted. \param n The number ofitems the to be inserted. \param item The element whose copies will be inserted. \throws "An allocation error" if memory is exhausted (std::bad_allocif the standard allocator is used). WhateverT::T(const T&)throws. WhateverT::operator = (const T&)throws. \par Exception Safety Basic. \par Iterator Invalidation Invalidates all iterators pointing to thecircular_buffer_space_optimized(except iterators equal toend()). \par Complexity Linear (inmin[capacity().%capacity(), size() + n]). \par Example Consider acircular_buffer_space_optimizedwith the capacity of 6 and the size of 4. Its internal buffer may look like the one below.
|1|2|3|4| | |
p ___^
After inserting 5 elements at the positionp:
insert(p, (size_t)5, 0);
actually only 4 elements get inserted and elements1and2are overwritten. This is due to the fact the insert operation preserves the capacity. After insertion the internal buffer looks like this:|0|0|0|0|3|4|
For comparison if the capacity would not be preserved the internal buffer would then result in|1|2|0|0|0|0|0|3|4|. \sa\link insert(iterator, param_value_type) insert(iterator, value_type)\endlink,insert(iterator, InputIterator, InputIterator),\link rinsert(iterator, param_value_type) rinsert(iterator, value_type)\endlink,\link rinsert(iterator, size_type, param_value_type) rinsert(iterator, size_type, value_type)\endlink,rinsert(iterator, InputIterator, InputIterator)*/ void insert(iterator pos, size_type n, param_value_type item) { size_type index = pos - begin(); check_low_capacity(n); circular_buffer::insert(begin() + index, n, item); } //! Insert the range [first, last)at the specified position. /*! \preposis a valid iterator pointing to thecircular_buffer_space_optimizedor its end.
Valid range[first, last)wherefirstandlastmeet the requirements of an InputIterator. \post Elements from the range[first + max[0, distance(first, last) - (pos - begin()) - reserve()], last)will be inserted at the positionpos.
The number ofmin[pos - begin(), max[0, distance(first, last) - reserve()]]elements will be overwritten at the beginning of thecircular_buffer_space_optimized.
(See Example for the explanation.)
The amount of allocated memory in the internal buffer may be predictively increased. \param pos An iterator specifying the position where the range will be inserted. \param first The beginning of the range to be inserted. \param last The end of the range to be inserted. \throws "An allocation error" if memory is exhausted (std::bad_allocif the standard allocator is used). WhateverT::T(const T&)throws or nothing ifT::T(T&&)is noexcept. \par Exception Safety Basic. \par Iterator Invalidation Invalidates all iterators pointing to thecircular_buffer_space_optimized(except iterators equal toend()). \par Complexity Linear (in[size() + std::distance(first, last)]; inmin[capacity().%capacity(), size() + std::distance(first, last)]if theInputIteratoris a RandomAccessIterator). \par Example Consider acircular_buffer_space_optimizedwith the capacity of 6 and the size of 4. Its internal buffer may look like the one below.
|1|2|3|4| | |
p ___^
After inserting a range of elements at the positionp:
int array[] = { 5, 6, 7, 8, 9 };insert(p, array, array + 5);
actually only elements6,7,8and9from the specified range get inserted and elements1and2are overwritten. This is due to the fact the insert operation preserves the capacity. After insertion the internal buffer looks like this:|6|7|8|9|3|4|
For comparison if the capacity would not be preserved the internal buffer would then result in|1|2|5|6|7|8|9|3|4|. \sa\link insert(iterator, param_value_type) insert(iterator, value_type)\endlink,\link insert(iterator, size_type, param_value_type) insert(iterator, size_type, value_type)\endlink,\link rinsert(iterator, param_value_type) rinsert(iterator, value_type)\endlink,\link rinsert(iterator, size_type, param_value_type) rinsert(iterator, size_type, value_type)\endlink,rinsert(iterator, InputIterator, InputIterator)*/ templatevoid insert(iterator pos, InputIterator first, InputIterator last) { insert(pos, first, last, is_integral ()); } //! Insert an element before the specified position. /*! \pre posis a valid iterator pointing to thecircular_buffer_space_optimizedor its end. \post Theitemwill be inserted before the positionpos.
If thecircular_buffer_space_optimizedis full, the last element will be overwritten. If thecircular_buffer_space_optimizedis full and thepospoints toend(), then theitemwill not be inserted. If the capacity is0, nothing will be inserted.
The amount of allocated memory in the internal buffer may be predictively increased. \param pos An iterator specifying the position before which theitemwill be inserted. \param item The element to be inserted. \return Iterator to the inserted element orend()if theitemis not inserted. (See the Effect.) \throws "An allocation error" if memory is exhausted (std::bad_allocif the standard allocator is used). WhateverT::T(const T&)throws. WhateverT::operator = (const T&)throws. \par Exception Safety Basic. \par Iterator Invalidation Invalidates all iterators pointing to thecircular_buffer_space_optimized(except iterators equal toend()). \par Complexity Linear (in the size of thecircular_buffer_space_optimized). \sa\link rinsert(iterator, size_type, param_value_type) rinsert(iterator, size_type, value_type)\endlink,rinsert(iterator, InputIterator, InputIterator),\link insert(iterator, param_value_type) insert(iterator, value_type)\endlink,\link insert(iterator, size_type, param_value_type) insert(iterator, size_type, value_type)\endlink,insert(iterator, InputIterator, InputIterator)*/ iterator rinsert(iterator pos, param_value_type item) { size_type index = pos - begin(); check_low_capacity(); return circular_buffer::rinsert(begin() + index, item); } //! Insert an element before the specified position. /*! \pre posis a valid iterator pointing to thecircular_buffer_space_optimizedor its end. \post Theitemwill be inserted before the positionpos.
If thecircular_buffer_space_optimizedis full, the last element will be overwritten. If thecircular_buffer_space_optimizedis full and thepospoints toend(), then theitemwill not be inserted. If the capacity is0, nothing will be inserted.
The amount of allocated memory in the internal buffer may be predictively increased. \param pos An iterator specifying the position before which theitemwill be inserted. \param item The element to be inserted. \return Iterator to the inserted element orend()if theitemis not inserted. (See the Effect.) \throws "An allocation error" if memory is exhausted (std::bad_allocif the standard allocator is used). WhateverT::T(const T&)throws or nothing ifT::T(T&&)is noexcept. \par Exception Safety Basic. \par Iterator Invalidation Invalidates all iterators pointing to thecircular_buffer_space_optimized(except iterators equal toend()). \par Complexity Linear (in the size of thecircular_buffer_space_optimized). \sa\link rinsert(iterator, size_type, param_value_type) rinsert(iterator, size_type, value_type)\endlink,rinsert(iterator, InputIterator, InputIterator),\link insert(iterator, param_value_type) insert(iterator, value_type)\endlink,\link insert(iterator, size_type, param_value_type) insert(iterator, size_type, value_type)\endlink,insert(iterator, InputIterator, InputIterator)*/ iterator rinsert(iterator pos, rvalue_type item) { size_type index = pos - begin(); check_low_capacity(); return circular_buffer::rinsert(begin() + index, boost::move(item)); } //! Insert an element before the specified position. /*! \pre posis a valid iterator pointing to thecircular_buffer_space_optimizedor its end. \post Theitemwill be inserted before the positionpos.
If thecircular_buffer_space_optimizedis full, the last element will be overwritten. If thecircular_buffer_space_optimizedis full and thepospoints toend(), then theitemwill not be inserted. If the capacity is0, nothing will be inserted.
The amount of allocated memory in the internal buffer may be predictively increased. \param pos An iterator specifying the position before which theitemwill be inserted. \return Iterator to the inserted element orend()if theitemis not inserted. (See the Effect.) \throws "An allocation error" if memory is exhausted (std::bad_allocif the standard allocator is used). WhateverT::T()throws. WhateverT::T(const T&)throws or nothing ifT::T(T&&)is noexcept. \par Exception Safety Basic. \par Iterator Invalidation Invalidates all iterators pointing to thecircular_buffer_space_optimized(except iterators equal toend()). \par Complexity Linear (in the size of thecircular_buffer_space_optimized). \sa\link rinsert(iterator, size_type, param_value_type) rinsert(iterator, size_type, value_type)\endlink,rinsert(iterator, InputIterator, InputIterator),\link insert(iterator, param_value_type) insert(iterator, value_type)\endlink,\link insert(iterator, size_type, param_value_type) insert(iterator, size_type, value_type)\endlink,insert(iterator, InputIterator, InputIterator)*/ iterator rinsert(iterator pos) { size_type index = pos - begin(); check_low_capacity(); return circular_buffer::rinsert(begin() + index); } //! Insert ncopies of theitembefore the specified position. /*! \preposis a valid iterator pointing to thecircular_buffer_space_optimizedor its end. \post The number ofmin[n, (end() - pos) + reserve()]elements will be inserted before the positionpos.
The number ofmin[end() - pos, max[0, n - reserve()]]elements will be overwritten at the end of thecircular_buffer_space_optimized.
(See Example for the explanation.)
The amount of allocated memory in the internal buffer may be predictively increased. \param pos An iterator specifying the position where theitems will be inserted. \param n The number ofitems the to be inserted. \param item The element whose copies will be inserted. \throws "An allocation error" if memory is exhausted (std::bad_allocif the standard allocator is used). WhateverT::T(const T&)throws. WhateverT::operator = (const T&)throws. \par Exception Safety Basic. \par Iterator Invalidation Invalidates all iterators pointing to thecircular_buffer_space_optimized(except iterators equal toend()). \par Complexity Linear (inmin[capacity().%capacity(), size() + n]). \par Example Consider acircular_buffer_space_optimizedwith the capacity of 6 and the size of 4. Its internal buffer may look like the one below.
|1|2|3|4| | |
p ___^
After inserting 5 elements before the positionp:
rinsert(p, (size_t)5, 0);
actually only 4 elements get inserted and elements3and4are overwritten. This is due to the fact the rinsert operation preserves the capacity. After insertion the internal buffer looks like this:|1|2|0|0|0|0|
For comparison if the capacity would not be preserved the internal buffer would then result in|1|2|0|0|0|0|0|3|4|. \sa\link rinsert(iterator, param_value_type) rinsert(iterator, value_type)\endlink,rinsert(iterator, InputIterator, InputIterator),\link insert(iterator, param_value_type) insert(iterator, value_type)\endlink,\link insert(iterator, size_type, param_value_type) insert(iterator, size_type, value_type)\endlink,insert(iterator, InputIterator, InputIterator)*/ void rinsert(iterator pos, size_type n, param_value_type item) { size_type index = pos - begin(); check_low_capacity(n); circular_buffer::rinsert(begin() + index, n, item); } //! Insert the range [first, last)before the specified position. /*! \preposis a valid iterator pointing to thecircular_buffer_space_optimizedor its end.
Valid range[first, last)wherefirstandlastmeet the requirements of an InputIterator. \post Elements from the range[first, last - max[0, distance(first, last) - (end() - pos) - reserve()])will be inserted before the positionpos.
The number ofmin[end() - pos, max[0, distance(first, last) - reserve()]]elements will be overwritten at the end of thecircular_buffer.
(See Example for the explanation.)
The amount of allocated memory in the internal buffer may be predictively increased. \param pos An iterator specifying the position where the range will be inserted. \param first The beginning of the range to be inserted. \param last The end of the range to be inserted. \throws "An allocation error" if memory is exhausted (std::bad_allocif the standard allocator is used). WhateverT::T(const T&)throws. WhateverT::operator = (const T&)throws. \par Exception Safety Basic. \par Iterator Invalidation Invalidates all iterators pointing to thecircular_buffer_space_optimized(except iterators equal toend()). \par Complexity Linear (in[size() + std::distance(first, last)]; inmin[capacity().%capacity(), size() + std::distance(first, last)]if theInputIteratoris a RandomAccessIterator). \par Example Consider acircular_buffer_space_optimizedwith the capacity of 6 and the size of 4. Its internal buffer may look like the one below.
|1|2|3|4| | |
p ___^
After inserting a range of elements before the positionp:
int array[] = { 5, 6, 7, 8, 9 };insert(p, array, array + 5);
actually only elements5,6,7and8from the specified range get inserted and elements3and4are overwritten. This is due to the fact the rinsert operation preserves the capacity. After insertion the internal buffer looks like this:|1|2|5|6|7|8|
For comparison if the capacity would not be preserved the internal buffer would then result in|1|2|5|6|7|8|9|3|4|. \sa\link rinsert(iterator, param_value_type) rinsert(iterator, value_type)\endlink,\link rinsert(iterator, size_type, param_value_type) rinsert(iterator, size_type, value_type)\endlink,\link insert(iterator, param_value_type) insert(iterator, value_type)\endlink,\link insert(iterator, size_type, param_value_type) insert(iterator, size_type, value_type)\endlink,insert(iterator, InputIterator, InputIterator)*/ templatevoid rinsert(iterator pos, InputIterator first, InputIterator last) { rinsert(pos, first, last, is_integral ()); } //! Remove an element at the specified position. /*! \pre posis a valid iterator pointing to thecircular_buffer_space_optimized(but not anend()). \post The element at the positionposis removed.
The amount of allocated memory in the internal buffer may be predictively decreased. \param pos An iterator pointing at the element to be removed. \return Iterator to the first element remaining beyond the removed element orend()if no such element exists. \throws "An allocation error" if memory is exhausted (std::bad_allocif the standard allocator is used). WhateverT::operator = (const T&)throws or nothing ifT::operator = (T&&)is noexcept. \par Exception Safety Basic. \par Iterator Invalidation Invalidates all iterators pointing to thecircular_buffer_space_optimized(except iterators equal toend()). \par Complexity Linear (in the size of thecircular_buffer_space_optimized). \saerase(iterator, iterator),rerase(iterator),rerase(iterator, iterator),clear()*/ iterator erase(iterator pos) { iterator it = circular_buffer::erase(pos); size_type index = it - begin(); check_high_capacity(); return begin() + index; } //! Erase the range [first, last). /*! \pre Valid range[first, last). \post The elements from the range[first, last)are removed. (Iffirst == lastnothing is removed.)
The amount of allocated memory in the internal buffer may be predictively decreased. \param first The beginning of the range to be removed. \param last The end of the range to be removed. \return Iterator to the first element remaining beyond the removed elements orend()if no such element exists. \throws "An allocation error" if memory is exhausted (std::bad_allocif the standard allocator is used). WhateverT::operator = (const T&)throws or nothing ifT::operator = (T&&)is noexcept. \par Exception Safety Basic. \par Iterator Invalidation Invalidates all iterators pointing to thecircular_buffer_space_optimized(except iterators equal toend()). \par Complexity Linear (in the size of thecircular_buffer_space_optimized). \saerase(iterator),rerase(iterator),rerase(iterator, iterator),clear()*/ iterator erase(iterator first, iterator last) { iterator it = circular_buffer::erase(first, last); size_type index = it - begin(); check_high_capacity(); return begin() + index; } //! Remove an element at the specified position. /*! \pre posis a valid iterator pointing to thecircular_buffer_space_optimized(but not anend()).
The amount of allocated memory in the internal buffer may be predictively decreased. \post The element at the positionposis removed. \param pos An iterator pointing at the element to be removed. \return Iterator to the first element remaining in front of the removed element orbegin()if no such element exists. \throws "An allocation error" if memory is exhausted (std::bad_allocif the standard allocator is used). WhateverT::operator = (const T&)throws or nothing ifT::operator = (T&&)is noexcept. \par Exception Safety Basic. \par Iterator Invalidation Invalidates all iterators pointing to thecircular_buffer_space_optimized(except iterators equal toend()). \par Complexity Linear (in the size of thecircular_buffer_space_optimized). \note Basically there is no difference betweenerase(iterator)and this method. It is implemented only for consistency with the basecircular_buffer. \saerase(iterator),erase(iterator, iterator),rerase(iterator, iterator),clear()*/ iterator rerase(iterator pos) { iterator it = circular_buffer::rerase(pos); size_type index = it - begin(); check_high_capacity(); return begin() + index; } //! Erase the range [first, last). /*! \pre Valid range[first, last). \post The elements from the range[first, last)are removed. (Iffirst == lastnothing is removed.)
The amount of allocated memory in the internal buffer may be predictively decreased. \param first The beginning of the range to be removed. \param last The end of the range to be removed. \return Iterator to the first element remaining in front of the removed elements orbegin()if no such element exists. \throws "An allocation error" if memory is exhausted (std::bad_allocif the standard allocator is used). WhateverT::operator = (const T&)throws or nothing ifT::operator = (T&&)is noexcept. \par Exception Safety Basic. \par Iterator Invalidation Invalidates all iterators pointing to thecircular_buffer_space_optimized(except iterators equal toend()). \par Complexity Linear (in the size of thecircular_buffer_space_optimized). \note Basically there is no difference betweenerase(iterator, iterator)and this method. It is implemented only for consistency with the base. \sa erase(iterator),erase(iterator, iterator),rerase(iterator),clear()*/ iterator rerase(iterator first, iterator last) { iterator it = circular_buffer::rerase(first, last); size_type index = it - begin(); check_high_capacity(); return begin() + index; } //! Remove all stored elements from the space optimized circular buffer. /*! \post size() == 0
The amount of allocated memory in the internal buffer may be predictively decreased. \throws "An allocation error" if memory is exhausted (std::bad_allocif the standard allocator is used). \par Exception Safety Basic. \par Iterator Invalidation Invalidates all iterators pointing to thecircular_buffer_space_optimized(except iterators equal toend()). \par Complexity Linear (in the size of thecircular_buffer_space_optimized). \sa~circular_buffer_space_optimized(),erase(iterator),erase(iterator, iterator),rerase(iterator),rerase(iterator, iterator)*/ void clear() { erase(begin(), end()); } private: // Helper methods /*! INTERNAL ONLY */ void adjust_min_capacity() { if (m_capacity_ctrl.min_capacity() > circular_buffer::capacity()) circular_buffer ::set_capacity(m_capacity_ctrl.min_capacity()); else check_high_capacity(); } /*! INTERNAL ONLY */ size_type ensure_reserve(size_type new_capacity, size_type buffer_size) const { if (buffer_size + new_capacity / 5 >= new_capacity) new_capacity *= 2; // ensure at least 20% reserve if (new_capacity > m_capacity_ctrl) return m_capacity_ctrl; return new_capacity; } /*! INTERNAL ONLY */ void check_low_capacity(size_type n = 1) { size_type new_size = size() + n; size_type new_capacity = circular_buffer ::capacity(); if (new_size > new_capacity) { if (new_capacity == 0) new_capacity = 1; for (; new_size > new_capacity; new_capacity *= 2) {} circular_buffer ::set_capacity( ensure_reserve(new_capacity, new_size)); } #if BOOST_CB_ENABLE_DEBUG this->invalidate_iterators_except(end()); #endif } /*! INTERNAL ONLY */ void check_high_capacity() { size_type new_capacity = circular_buffer ::capacity(); while (new_capacity / 3 >= size()) { // (new_capacity / 3) -> avoid oscillations new_capacity /= 2; if (new_capacity <= m_capacity_ctrl.min_capacity()) { new_capacity = m_capacity_ctrl.min_capacity(); break; } } circular_buffer ::set_capacity( ensure_reserve(new_capacity, size())); #if BOOST_CB_ENABLE_DEBUG this->invalidate_iterators_except(end()); #endif } /*! INTERNAL ONLY */ void reduce_capacity(const true_type&) { circular_buffer ::set_capacity((std::max)(m_capacity_ctrl.min_capacity(), size())); } /*! INTERNAL ONLY */ void reduce_capacity(const false_type&) {} /*! INTERNAL ONLY */ static size_type init_capacity(const capacity_type& capacity_ctrl, size_type n) { BOOST_CB_ASSERT(capacity_ctrl.capacity() >= n); // check for capacity lower than n return (std::max)(capacity_ctrl.min_capacity(), n); } /*! INTERNAL ONLY */ template static size_type init_capacity(const capacity_type& capacity_ctrl, IntegralType n, IntegralType, const true_type&) { return init_capacity(capacity_ctrl, static_cast (n)); } /*! INTERNAL ONLY */ template static size_type init_capacity(const capacity_type& capacity_ctrl, Iterator first, Iterator last, const false_type&) { BOOST_CB_IS_CONVERTIBLE(Iterator, value_type); // check for invalid iterator type #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x581)) return init_capacity(capacity_ctrl, first, last, std::iterator_traits ::iterator_category()); #else return init_capacity( capacity_ctrl, first, last, BOOST_DEDUCED_TYPENAME std::iterator_traits ::iterator_category()); #endif } /*! INTERNAL ONLY */ template static size_type init_capacity(const capacity_type& capacity_ctrl, InputIterator, InputIterator, const std::input_iterator_tag&) { return capacity_ctrl.capacity(); } /*! INTERNAL ONLY */ template static size_type init_capacity(const capacity_type& capacity_ctrl, ForwardIterator first, ForwardIterator last, const std::forward_iterator_tag&) { BOOST_CB_ASSERT(std::distance(first, last) >= 0); // check for wrong range return (std::max)(capacity_ctrl.min_capacity(), (std::min)(capacity_ctrl.capacity(), static_cast (std::distance(first, last)))); } /*! INTERNAL ONLY */ template void insert(const iterator& pos, IntegralType n, IntegralType item, const true_type&) { insert(pos, static_cast (n), static_cast (item)); } /*! INTERNAL ONLY */ template void insert(const iterator& pos, Iterator first, Iterator last, const false_type&) { size_type index = pos - begin(); check_low_capacity(std::distance(first, last)); circular_buffer ::insert(begin() + index, first, last); } /*! INTERNAL ONLY */ template void rinsert(const iterator& pos, IntegralType n, IntegralType item, const true_type&) { rinsert(pos, static_cast (n), static_cast (item)); } /*! INTERNAL ONLY */ template void rinsert(const iterator& pos, Iterator first, Iterator last, const false_type&) { size_type index = pos - begin(); check_low_capacity(std::distance(first, last)); circular_buffer ::rinsert(begin() + index, first, last); } }; // Non-member functions //! Test two space optimized circular buffers for equality. template inline bool operator == (const circular_buffer_space_optimized & lhs, const circular_buffer_space_optimized & rhs) { return lhs.size() == rhs.size() && std::equal(lhs.begin(), lhs.end(), rhs.begin()); } //! Lexicographical comparison. template inline bool operator < (const circular_buffer_space_optimized & lhs, const circular_buffer_space_optimized & rhs) { return std::lexicographical_compare( lhs.begin(), lhs.end(), rhs.begin(), rhs.end()); } #if !defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING) || BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1310)) //! Test two space optimized circular buffers for non-equality. template inline bool operator != (const circular_buffer_space_optimized & lhs, const circular_buffer_space_optimized & rhs) { return !(lhs == rhs); } //! Lexicographical comparison. template inline bool operator > (const circular_buffer_space_optimized & lhs, const circular_buffer_space_optimized & rhs) { return rhs < lhs; } //! Lexicographical comparison. template inline bool operator <= (const circular_buffer_space_optimized & lhs, const circular_buffer_space_optimized & rhs) { return !(rhs < lhs); } //! Lexicographical comparison. template inline bool operator >= (const circular_buffer_space_optimized & lhs, const circular_buffer_space_optimized & rhs) { return !(lhs < rhs); } //! Swap the contents of two space optimized circular buffers. template inline void swap(circular_buffer_space_optimized & lhs, circular_buffer_space_optimized & rhs) BOOST_NOEXCEPT { lhs.swap(rhs); } #endif // #if !defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING) || BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1310)) } // namespace boost #endif // #if !defined(BOOST_CIRCULAR_BUFFER_SPACE_OPTIMIZED_HPP)