Space Optimized Circular Buffer

circular_buffer_space_optimized<T, Alloc>

Boost

Contents

Description
Synopsis
Rationale
Header Files
Modeled concepts
Template Parameters, Members and StandaloneFunctions
Semantics
See also
Acknowledgments

Description

The circular_buffer_space_optimized container is an adaptor of the circular_buffer. The functionality of the circular_buffer_space_optimized is similar to the base circular_buffer except it does not allocate memory at once when created rather it allocates memory as needed. (The predictive memory allocation is similar to typical std::vector implementation.) Moreover the memory is automatically freed as the size of the container decreases.

Space Optimized Circular Buffer
Figure: The memory allocation process of the space optimized circular buffer. The min_capacity represents the minimal guaranteed amount of allocated memory. The allocated memory will never drop under this value. By default the min_capacity is set to 0.

Synopsis

Note that some of the links point to the original circular_buffer if the functionality is the same.

namespace boost {

template <class T, class Alloc>
class circular_buffer_space_optimized
{
public:
   typedef typename Alloc::value_type value_type;
   typedef typename Alloc::pointer pointer;
   typedef typename Alloc::const_pointer const_pointer;
   typedef typename Alloc::reference reference;
   typedef typename Alloc::const_reference const_reference;
   typedef typename Alloc::size_type size_type;
   typedef typename Alloc::difference_type difference_type;
   typedef Alloc allocator_type;
   typedef implementation-defined const_iterator;
   typedef implementation-defined iterator;
   typedef reverse_iterator<const_iterator> const_reverse_iterator;
   typedef reverse_iterator<iterator> reverse_iterator;
   typedef std::pair<pointer, size_type> array_range;
   typedef std::pair<const_pointer, size_type> const_array_range;
   typedef implementation-defined capacity_type;

   explicit circular_buffer_space_optimized(const allocator_type& alloc = allocator_type());
   explicit circular_buffer_space_optimized(capacity_type capacity_ctrl, const allocator_type& alloc = allocator_type());
   circular_buffer_space_optimized(capacity_type capacity_ctrl, const_reference item, const allocator_type& alloc = allocator_type());
   circular_buffer_space_optimized(capacity_type capacity_ctrl, size_type n, const_reference item, const allocator_type& alloc = allocator_type());
   circular_buffer_space_optimized(const circular_buffer_space_optimized<T, Alloc>& cb);
   template <class InputIterator>
      circular_buffer_space_optimized(InputIterator first, InputIterator last, const allocator_type& alloc = allocator_type());
   template <class InputIterator>
      circular_buffer_space_optimized(capacity_type capacity_ctrl, InputIterator first, InputIterator last, const allocator_type& alloc = allocator_type());
   ~circular_buffer_space_optimized();

   allocator_type get_allocator() const;
   allocator_type& get_allocator();
   iterator begin();
   iterator end();
   const_iterator begin() const;
   const_iterator end() const;
   reverse_iterator rbegin();
   reverse_iterator rend();
   const_reverse_iterator rbegin() const;
   const_reverse_iterator rend() const;
   reference operator[](size_type index);
   const_reference operator[](size_type index) const;
   reference at(size_type index);
   const_reference at(size_type index) const;
   reference front();
   reference back();
   const_reference front() const;
   const_reference back() const;
   array_range array_one();
   array_range array_two();
   const_array_range array_one() const;
   const_array_range array_two() const;
   pointer linearize();
   size_type size() const;
   size_type max_size() const;
   bool empty() const;
   bool full() const;
   size_type reserve() const;
   const capacity_type& capacity() const;
   void set_capacity(const capacity_type& capacity_ctrl);
   void resize(size_type new_size, const_reference item = value_type());
   void rset_capacity(const capacity_type& capacity_ctrl);
   void rresize(size_type new_size, const_reference item = value_type());
   circular_buffer_space_optimized<T, Alloc>& operator=(const circular_buffer_space_optimized<T, Alloc>& cb);
   void assign(size_type n, const_reference item);
   void assign(capacity_type capacity_ctrl, size_type n, const_reference item);
   template <class InputIterator>
      void assign(InputIterator first, InputIterator last);
   template <class InputIterator>
      void assign(capacity_type capacity_ctrl, InputIterator first, InputIterator last);
   void swap(circular_buffer_space_optimized<T, Alloc>& cb);
   void push_back(const_reference item = value_type());
   void push_front(const_reference item = value_type());
   void pop_back();
   void pop_front();
   iterator insert(iterator pos, const_reference item = value_type());
   void insert(iterator pos, size_type n, const_reference item);
   template <class InputIterator>
      void insert(iterator pos, InputIterator first, InputIterator last);
   iterator rinsert(iterator pos, const_reference item = value_type());
   void rinsert(iterator pos, size_type n, const_reference item);
   template <class InputIterator>
      void rinsert(iterator pos, InputIterator first, InputIterator last);
   iterator erase(iterator pos);
   iterator erase(iterator first, iterator last);
   iterator rerase(iterator pos);
   iterator rerase(iterator first, iterator last);
   void clear();
};

template <class T, class Alloc>
   bool operator==(const circular_buffer_space_optimized<T, Alloc>& lhs, const circular_buffer_space_optimized<T, Alloc>& rhs);
template <class T, class Alloc>
   bool operator<(const circular_buffer_space_optimized<T, Alloc>& lhs, const circular_buffer_space_optimized<T, Alloc>& rhs);
template <class T, class Alloc>
   bool operator!=(const circular_buffer_space_optimized<T, Alloc>& lhs, const circular_buffer_space_optimized<T, Alloc>& rhs);
template <class T, class Alloc>
   bool operator>(const circular_buffer_space_optimized<T, Alloc>& lhs, const circular_buffer_space_optimized<T, Alloc>& rhs);
template <class T, class Alloc>
   bool operator<=(const circular_buffer_space_optimized<T, Alloc>& lhs, const circular_buffer_space_optimized<T, Alloc>& rhs);
template <class T, class Alloc>
   bool operator>=(const circular_buffer_space_optimized<T, Alloc>& lhs, const circular_buffer_space_optimized<T, Alloc>& rhs);
template <class T, class Alloc>
   void swap(circular_buffer_space_optimized<T, Alloc>& lhs, circular_buffer_space_optimized<T, Alloc>& rhs);

} // namespace boost

Rationale

The auto-resizing mode of the space optimized circular buffer can be useful in situations when the container can possibly store large number of elements but most of its lifetime the container stores just few of them. The usage of the circular_buffer_space_optimized will result in decreased memory consumption and can improve the CPU cache effectiveness.

Header Files

The circular_buffer_space_optimized is defined in the file boost/circular_buffer.hpp . There is also a forward declaration for the circular_buffer_space_optimized in the header file boost/circular_buffer_fwd.hpp .

Modeled concepts

Random AccessContainer, Front Insertion Sequence and Back Insertion Sequence.

Template Parameters, Members and Friend Functions

Template parameters, members and friend functions of the circular_buffer_space_optimized are almost the same as for the base circular_buffer . Refer the circular_buffer documentation and also its source code documentation for a detailed description.

Type Description
capacity_type Capacity controller of the space optimized circular buffer.
class capacity_control {
   size_type m_capacity;
   size_type m_min_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; }
};
Precondition:
capacity >= min_capacity
The m_capacity represents the capacity of the circular_buffer_space_optimized and the m_min_capacity determines the minimal allocated size of its internal buffer. The converting constructor of the capacity_control allows implicit conversion from size_type-like types which ensures compatibility of creating an instance of the circular_buffer_space_optimized with other STL containers. On the other hand the operator size_type() (returning m_capacity) provides implicit conversion to the size_type which allows to treat the capacity of the circular_buffer_space_optimized the same way as in the circular_buffer.

The specific methods of the circular_buffer_space_optimized are listed below.

Constructors

explicit circular_buffer_space_optimized(const allocator_type& alloc = allocator_type());

Create an empty space optimized circular buffer with a maximum capacity.
Effect:
capacity().capacity() == max_size() && capacity().min_capacity() == 0 && size() == 0

There is no memory allocated in the internal buffer after execution of this constructor.
Parameter(s):
alloc
The allocator.
Throws:
Nothing.
Complexity:
Constant.
explicit circular_buffer_space_optimized(capacity_type capacity_ctrl, const allocator_type& alloc = allocator_type());

Create an empty space optimized circular buffer with the specified capacity.
Effect:
capacity() == capacity_ctrl && size() == 0
Parameter(s):
capacity_ctrl
The capacity controller representing the maximum number of elements which can be stored in the circular_buffer_space_optimized and the minimal allocated size of the internal buffer.
alloc
The allocator.
Throws:
An allocation error if memory is exhausted (std::bad_alloc if the standard allocator is used).
Complexity:
Constant.
circular_buffer_space_optimized(capacity_type capacity_ctrl, const_reference item, const allocator_type& alloc = allocator_type());

Create a full space optimized circular buffer with the specified capacity (and the minimal guaranteed amount of allocated memory) filled with capacity_ctrl.capacity() copies of item.
Effect:
capacity() == capacity_ctrl && full() && (*this)[0] == item && (*this)[1] == item && ... && (*this) [capacity_ctrl.capacity() - 1] == item
Parameter(s):
capacity_ctrl
The capacity controller representing the maximum number of elements which can be stored in the circular_buffer_space_optimized and the minimal allocated size of the internal buffer.
item
The element the created circular_buffer_space_optimized will be filled with.
alloc
The allocator.
Throws:
An allocation error if memory is exhausted (std::bad_alloc if the standard allocator is used).
Whatever T::T(const T&) throws.
Complexity:
Linear (in the capacity_ctrl.capacity()).
circular_buffer_space_optimized(capacity_type capacity_ctrl, size_type n, const_reference item, const allocator_type& alloc = allocator_type());

Create a space optimized circular buffer with the specified capacity (and the minimal guaranteed amount of allocated memory) filled with n copies of item.
Precondition:
capacity_ctrl.capacity() >= n
Effect:
capacity() == capacity_ctrl && size() == n && (*this)[0] == item && (*this)[1] == item && ... && (*this)[n - 1] == item

Allocates at least as much memory as specified by the capacity_ctrl.min_capacity().
Parameter(s):
capacity_ctrl
The capacity controller representing the maximum number of elements which can be stored in the circular_buffer_space_optimized and the minimal allocated size of the internal buffer.
n
The number of elements the created circular_buffer_space_optimized will be filled with.
item
The element the created circular_buffer_space_optimized will be filled with.
alloc
The allocator.
Throws:
An allocation error if memory is exhausted (std::bad_alloc if the standard allocator is used).
Whatever T::T(const T&) throws.
Complexity:
Linear (in the n).
circular_buffer_space_optimized(const circular_buffer_space_optimized<T,Alloc>& cb);

The copy constructor.

Creates a copy of the specified circular_buffer_space_optimized.

Effect:
*this == cb

Allocates the exact amount of memory to store the content of cb.
Parameter(s):
cb
The circular_buffer_space_optimized to be copied.
Throws:
An allocation error if memory is exhausted (std::bad_alloc if the standard allocator is used).
Whatever T::T(const T&) throws.
Complexity:
Linear (in the size of cb).
template <class InputIterator>
circular_buffer_space_optimized(InputIterator first, InputIterator last, const allocator_type& alloc = allocator_type());


Create a full space optimized circular buffer filled with a copy of the range.
Precondition:
Valid range [first, last).
first and last have to meet the requirements of InputIterator.
Effect:
capacity().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)
Parameter(s):
first
The beginning of the range to be copied.
last
The end of the range to be copied.
alloc
The allocator.
Throws:
An allocation error if memory is exhausted (std::bad_alloc if the standard allocator is used).
Whatever T::T(const T&) throws.
Complexity:
Linear (in the std::distance(first, last)).
template <class InputIterator>
circular_buffer_space_optimized(capacity_type capacity_ctrl, InputIterator first, InputIterator last, const allocator_type& alloc = allocator_type());


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.
Precondition:
Valid range [first, last).
first and last have to meet the requirements of InputIterator.
Effect:
capacity() == 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)

Allocates at least as much memory as specified by the capacity_ctrl.min_capacity().

If the number of items to be copied from the range [first, last) is greater than the specified capacity_ctrl.capacity() then only elements from the range [last - capacity_ctrl.capacity(), last) will be copied.
Parameter(s):
capacity_ctrl
The capacity controller representing the maximum number of elements which can be stored in the circular_buffer_space_optimized and the minimal allocated size of the internal buffer.
first
The beginning of the range to be copied.
last
The end of the range to be copied.
alloc
The allocator.
Throws:
An allocation error if memory is exhausted (std::bad_alloc if the standard allocator is used).
Whatever T::T(const T&) throws.
Complexity:
Linear (in the capacity_ctrl.capacity()/std::distance(first, last)).
~circular_buffer_space_optimized();

The destructor.

Destroys the circular_buffer_space_optimized.

Throws:
Nothing.
Iterator Invalidation:
Invalidates all iterators pointing to the circular_buffer_space_optimized (including iterators equal to end()).
Complexity:
Linear (in the size of the circular_buffer_space_optimized).
See Also:
clear()

Public Member Functions

bool full() const;

Is the circular_buffer_space_optimized full?
Returns:
true if the number of elements stored in the circular_buffer_space_optimized equals the capacity of the circular_buffer_space_optimized; false otherwise.
Throws:
Nothing.
Exception Safety:
No-throw.
Iterator Invalidation:
Does not invalidate any iterators.
Complexity:
Constant (in the size of the circular_buffer_space_optimized).
See Also:
empty()
size_type reserve() const;

Get the maximum number of elements which can be inserted into the circular_buffer_space_optimized without overwriting any of already stored elements.
Returns:
capacity() - size()
Throws:
Nothing.
Exception Safety:
No-throw.
Iterator Invalidation:
Does not invalidate any iterators.
Complexity:
Constant (in the size of the circular_buffer_space_optimized).
See Also:
capacity(), size(), max_size()
const capacity_type& capacity() const;

Get the capacity of the circular_buffer_space_optimized.
Returns:
The capacity controller representing the maximum number of elements which can be stored in the circular_buffer_space_optimized and the minimal allocated size of the internal buffer.
Throws:
Nothing.
Exception Safety:
No-throw.
Iterator Invalidation:
Does not invalidate any iterators.
Complexity:
Constant (in the size of the circular_buffer_space_optimized).
See Also:
reserve(), size(), max_size(), set_capacity()
void set_capacity(const capacity_type& capacity_ctrl);

Change the capacity (and the minimal guaranteed amount of allocated memory) of the circular_buffer_space_optimized.
Effect:
capacity() == capacity_ctrl && size() <= capacity_ctrl.capacity()

If the current number of elements stored in the circular_buffer_space_optimized is 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 to capacity_ctrl.capacity().

If the current number of elements stored in the circular_buffer_space_optimized is lower than than the new capacity the allocated memory (in the internal buffer) may be accommodated as necessary but it will never drop below capacity_ctrl.min_capacity().
Parameter(s):
capacity_ctrl
The new capacity controller.
Throws:
An allocation error if memory is exhausted (std::bad_alloc if the standard allocator is used).
Whatever T::T(const T&) throws.
Exception Safety:
Strong.
Iterator Invalidation:
Invalidates all iterators pointing to the circular_buffer_space_optimized (except iterators equal to end()).
Complexity:
Linear (in the size/new capacity of the circular_buffer_space_optimized).
Note:
To explicitly clear the extra allocated memory use the shrink-to-fit technique:

boost::circular_buffer_space_optimized<int> cb(1000);
...
boost::circular_buffer_space_optimized<int>(cb).swap(cb);


For more information about the shrink-to-fit technique in STL see http://www.gotw.ca/gotw/054.htm.
See Also:
rset_capacity(), resize()
void resize(size_type new_size, const_reference item = value_type());

Change the size of the circular_buffer_space_optimized.
Effect:
size() == new_size && capacity().capacity() >= new_size

If the new size is greater than the current size, copies of item will be inserted at the back of the of the circular_buffer_space_optimized in order to achieve the desired size. In the case the resulting size exceeds the current capacity the capacity will be set to new_size.

If the current number of elements stored in the circular_buffer_space_optimized is greater than the desired new size then number of [size() - new_size] last elements will be removed. (The capacity will remain unchanged.)
Parameter(s):
new_size
The new size.
item
The element the circular_buffer_space_optimized will be filled with in order to gain the requested size. (See the Effect.)
Throws:
An allocation error if memory is exhausted (std::bad_alloc if the standard allocator is used).
Whatever T::T(const T&) throws.
Exception Safety:
Basic.
Iterator Invalidation:
Invalidates all iterators pointing to the circular_buffer_space_optimized (except iterators equal to end()).
Complexity:
Linear (in the new size of the circular_buffer_space_optimized).
See Also:
rresize(), set_capacity()
void rset_capacity(const capacity_type& capacity_ctrl);

Change the capacity (and the minimal guaranteed amount of allocated memory) of the circular_buffer_space_optimized.
Effect:
capacity() == capacity_ctrl && size() <= capacity_ctrl

If the current number of elements stored in the circular_buffer_space_optimized is 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 to capacity_ctrl.capacity().

If the current number of elements stored in the circular_buffer_space_optimized is lower than than the new capacity the allocated memory (in the internal buffer) may be accommodated as necessary but it will never drop below capacity_ctrl.min_capacity().
Parameter(s):
capacity_ctrl
The new capacity controller.
Throws:
An allocation error if memory is exhausted (std::bad_alloc if the standard allocator is used).
Whatever T::T(const T&) throws.
Exception Safety:
Strong.
Iterator Invalidation:
Invalidates all iterators pointing to the circular_buffer_space_optimized (except iterators equal to end()).
Complexity:
Linear (in the size/new capacity of the circular_buffer_space_optimized).
See Also:
set_capacity(), rresize()
void rresize(size_type new_size, const_reference item = value_type());

Change the size of the circular_buffer_space_optimized.
Effect:
size() == new_size && capacity().capacity() >= new_size

If the new size is greater than the current size, copies of item will be inserted at the front of the of the circular_buffer_space_optimized in order to achieve the desired size. In the case the resulting size exceeds the current capacity the capacity will be set to new_size.

If the current number of elements stored in the circular_buffer_space_optimized is greater than the desired new size then number of [size() - new_size] first elements will be removed. (The capacity will remain unchanged.)
Parameter(s):
new_size
The new size.
item
The element the circular_buffer_space_optimized will be filled with in order to gain the requested size. (See the Effect.)
Throws:
An allocation error if memory is exhausted (std::bad_alloc if the standard allocator is used).
Whatever T::T(const T&) throws.
Exception Safety:
Basic.
Iterator Invalidation:
Invalidates all iterators pointing to the circular_buffer_space_optimized (except iterators equal to end()).
Complexity:
Linear (in the new size of the circular_buffer_space_optimized).
See Also:
rresize(), set_capacity()
circular_buffer_space_optimized<T,Alloc>& operator=(const circular_buffer_space_optimized<T,Alloc>& cb);

The assign operator.

Makes this circular_buffer_space_optimized to become a copy of the specified circular_buffer_space_optimized.

Effect:
*this == cb
Parameter(s):
cb
The circular_buffer_space_optimized to be copied.
Throws:
An allocation error if memory is exhausted (std::bad_alloc if the standard allocator is used).
Whatever T::T(const T&) throws.
Exception Safety:
Strong.
Iterator Invalidation:
Invalidates all iterators pointing to this circular_buffer_space_optimized (except iterators equal to end()).
Complexity:
Linear (in the size of cb).
See Also:
assign(size_type, const_reference), assign(capacity_type, size_type, const_reference), assign(InputIterator, InputIterator), assign(capacity_type, InputIterator, InputIterator)
void assign(size_type n, const_reference item);

Assign n items into the space optimized circular buffer.

The content of the circular_buffer_space_optimized will be removed and replaced with n copies of the item.

Effect:
capacity().capacity() == n && capacity().min_capacity() == 0 && size() == n && (*this)[0] == item && (*this)[1] == item && ... && (*this) [n - 1] == item
Parameter(s):
n
The number of elements the circular_buffer_space_optimized will be filled with.
item
The element the circular_buffer_space_optimized will be filled with.
Throws:
An allocation error if memory is exhausted (std::bad_alloc if the standard allocator is used).
Whatever T::T(const T&) throws.
Exception Safety:
Basic.
Iterator Invalidation:
Invalidates all iterators pointing to the circular_buffer_space_optimized (except iterators equal to end()).
Complexity:
Linear (in the n).
See Also:
operator=, assign(capacity_type, size_type, const_reference), assign(InputIterator, InputIterator), assign(capacity_type, InputIterator, InputIterator)
void assign(capacity_type capacity_ctrl, size_type n, const_reference item);

Assign n items into the space optimized circular buffer specifying the capacity.

The capacity of the circular_buffer_space_optimized will be set to the specified value and the content of the circular_buffer_space_optimized will be removed and replaced with n copies of the item.

Precondition:
capacity_ctrl.capacity() >= n
Effect:
capacity() == capacity_ctrl && size() == n && (*this)[0] == item && (*this)[1] == item && ... && (*this) [n - 1] == item

The amount of allocated memory will be max[n, capacity_ctrl.min_capacity()].
Parameter(s):
capacity_ctrl
The new capacity controller.
n
The number of elements the circular_buffer_space_optimized will be filled with.
item
The element the circular_buffer_space_optimized will be filled with.
Throws:
An allocation error if memory is exhausted (std::bad_alloc if the standard allocator is used).
Whatever T::T(const T&) throws.
Exception Safety:
Basic.
Iterator Invalidation:
Invalidates all iterators pointing to the circular_buffer_space_optimized (except iterators equal to end()).
Complexity:
Linear (in the n).
See Also:
operator=, assign(size_type, const_reference), assign(InputIterator, InputIterator), assign(capacity_type, InputIterator, InputIterator)
template <class InputIterator>
void assign(InputIterator first, InputIterator last);


Assign a copy of the range into the space optimized circular buffer.

The content of the circular_buffer_space_optimized will be removed and replaced with copies of elements from the specified range.

Precondition:
Valid range [first, last).
first and last have to meet the requirements of InputIterator.
Effect:
capacity().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)
Parameter(s):
first
The beginning of the range to be copied.
last
The end of the range to be copied.
Throws:
An allocation error if memory is exhausted (std::bad_alloc if the standard allocator is used).
Whatever T::T(const T&) throws.
Exception Safety:
Basic.
Iterator Invalidation:
Invalidates all iterators pointing to the circular_buffer_space_optimized (except iterators equal to end()).
Complexity:
Linear (in the std::distance(first, last)).
See Also:
operator=, assign(size_type, const_reference), assign(capacity_type, size_type, const_reference), assign(capacity_type, InputIterator, InputIterator)
template <class InputIterator>
void assign(capacity_type capacity_ctrl, InputIterator first, InputIterator last);


Assign a copy of the range into the space optimized circular buffer specifying the capacity.

The capacity of the circular_buffer_space_optimized will be set to the specified value and the content of the circular_buffer_space_optimized will be removed and replaced with copies of elements from the specified range.

Precondition:
Valid range [first, last).
first and last have to meet the requirements of InputIterator.
Effect:
capacity() == 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 specified capacity then only elements from the range [last - capacity, last) will be copied.

The amount of allocated memory will be max[std::distance(first, last), capacity_ctrl.min_capacity()].
Parameter(s):
capacity_ctrl
The new capacity controller.
first
The beginning of the range to be copied.
last
The end of the range to be copied.
Throws:
An allocation error if memory is exhausted (std::bad_alloc if the standard allocator is used).
Whatever T::T(const T&) throws.
Exception Safety:
Basic.
Iterator Invalidation:
Invalidates all iterators pointing to the circular_buffer_space_optimized (except iterators equal to end()).
Complexity:
Linear (in the std::distance(first, last)).
See Also:
operator=, assign(size_type, const_reference), assign(capacity_type, size_type, const_reference), assign(InputIterator, InputIterator)
void swap(circular_buffer_space_optimized<T,Alloc>& cb);

See the circular_buffer source documentation.

void push_back(const_reference item = value_type());

See the circular_buffer source documentation.
Warning:
The rules for iterator invalidation differ from the original circular_buffer. See the documentation.
void push_front(const_reference item = value_type());

See the circular_buffer source documentation.
Warning:
The rules for iterator invalidation differ from the original circular_buffer. See the documentation.
void pop_back();

See the circular_buffer source documentation.
Warning:
The rules for iterator invalidation differ from the original circular_buffer. See the documentation.
void pop_front();

See the circular_buffer source documentation.
Warning:
The rules for iterator invalidation differ from the original circular_buffer. See the documentation.
iterator insert(iterator pos, const_reference item = value_type());

See the circular_buffer source documentation.
Warning:
The rules for iterator invalidation differ from the original circular_buffer. See the documentation.
void insert(iterator pos, size_type n, const_reference item);

See the circular_buffer source documentation.
Warning:
The rules for iterator invalidation differ from the original circular_buffer. See the documentation.
template <class InputIterator>
void insert(iterator pos, InputIterator first, InputIterator last);


See the circular_buffer source documentation.
Warning:
The rules for iterator invalidation differ from the original circular_buffer. See the documentation.
iterator rinsert(iterator pos, const_reference item = value_type());

See the circular_buffer source documentation.
Warning:
The rules for iterator invalidation differ from the original circular_buffer. See the documentation.
void rinsert(iterator pos, size_type n, const_reference item);

See the circular_buffer source documentation.
Warning:
The rules for iterator invalidation differ from the original circular_buffer. See the documentation.
template <class InputIterator>
void rinsert(iterator pos, InputIterator first, InputIterator last);


See the circular_buffer source documentation.
Warning:
The rules for iterator invalidation differ from the original circular_buffer. See the documentation.
iterator erase(iterator pos);

See the circular_buffer source documentation.
Warning:
The rules for iterator invalidation differ from the original circular_buffer. See the documentation.
iterator erase(iterator first, iterator last);

See the circular_buffer source documentation.
Warning:
The rules for iterator invalidation differ from the original circular_buffer. See the documentation.
iterator rerase(iterator pos);

See the circular_buffer source documentation.
Warning:
The rules for iterator invalidation differ from the original circular_buffer. See the documentation.
iterator rerase(iterator first, iterator last);

See the circular_buffer source documentation.
Warning:
The rules for iterator invalidation differ from the original circular_buffer. See the documentation.
void clear();

See the circular_buffer source documentation.

Semantics

TODO remove this section

The behaviour of memory auto-resizing is as follows:

The semantics of the circular_buffer_space_optimized then follows the semantics of the base circular_buffer except the invalidation rules.

The rule for iterator invalidation for circular_buffer_space_optimized is as follows:

See also

boost::circular_buffer, std::vector

Acknowledgments

The idea of the space optimized circular buffer has been introduced by Pavel Vozenilek.