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; } };
capacity >= min_capacity
The capacity() represents the capacity of the circular_buffer_space_optimized and the min_capacity() determines the minimal allocated size of its internal buffer.
capacity()
circular_buffer_space_optimized
min_capacity()
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() 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.
capacity_control
size_type
%size_type()
circular_buffer
true
false
empty()
capacity().%capacity() - size()
size()
max_size()
reserve()
set_capacity(const capacity_type&)
capacity() == capacity_ctrl \&\& size() \<= capacity_ctrl.capacity()
[size() - capacity_ctrl.capacity()]
capacity_ctrl.capacity()
capacity_ctrl.min_capacity()
std::bad_alloc
T::T(const T&)
end()
min[size(), capacity_ctrl.%capacity()]
boost::%circular_buffer_space_optimized\ cb(1000); ... boost::%circular_buffer_space_optimized\(cb).swap(cb);
rset_capacity(const capacity_type&)
\link resize() resize(size_type, const_reference)\endlink
size() == new_size \&\& capacity().%capacity() >= new_size
item
new_size
[size() - new_size]
\link rresize() rresize(size_type, const_reference)\endlink
capacity() == capacity_ctrl \&\& size() \<= capacity_ctrl
capacity().%capacity() == max_size() \&\& capacity().min_capacity() == 0 \&\& size() == 0
capacity() == capacity_ctrl \&\& size() == 0
capacity_ctrl.%capacity()
capacity() == capacity_ctrl \&\& full() \&\& (*this)[0] == item \&\& (*this)[1] == item \&\& ... \&\& (*this) [capacity_ctrl.%capacity() - 1] == item
n
capacity_ctrl.%capacity() >= n
capacity() == capacity_ctrl \&\& size() == n \&\& (*this)[0] == item \&\& (*this)[1] == item \&\& ... \&\& (*this)[n - 1] == item
max[n, capacity_ctrl.min_capacity()]
*this == cb
cb.size()
cb
[first, last)
first
last
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)
std::distance(first, last)
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)
[last - capacity_ctrl.%capacity(), last)
max[capacity_ctrl.min_capacity(), min[capacity_ctrl.%capacity(), std::distance(first, last)]]
min[capacity_ctrl.%capacity(), std::distance(first, last)]
InputIterator
clear()
\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)
capacity().%capacity() == n \&\& capacity().min_capacity() == 0 \&\& size() == n \&\& (*this)[0] == item \&\& (*this)[1] == item \&\& ... \&\& (*this) [n - 1] == item
operator=
capacity() == capacity_ctrl \&\& size() == n \&\& (*this)[0] == item \&\& (*this)[1] == item \&\& ... \&\& (*this) [n - 1] == item
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)
capacity() == capacity_ctrl \&\& size() \<= std::distance(first, last) \&\& (*this)[0]== *(last - capacity) \&\& (*this)[1] == *(last - capacity + 1) \&\& ... \&\& (*this)[capacity - 1] == *(last - 1)
capacity
[last - capacity, last)
max[std::distance(first, last), capacity_ctrl.min_capacity()]
this
\link swap(circular_buffer&, circular_buffer&) swap(circular_buffer_space_optimized&, circular_buffer_space_optimized&)\endlink
capacity().%capacity() > 0
back() == item
0
\link push_front() push_front(const_reference)\endlink
pop_back()
pop_front()
front() == item
\link push_back() push_back(const_reference)\endlink
!empty()
pos
begin()
T::operator = (const T&)
\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)
min[n, (pos - begin()) + reserve()]
min[pos - begin(), max[0, n - reserve()]]
min[capacity().%capacity(), size() + n]
|1|2|3|4| | |
p ---^
p
insert(p, (size_t)5, 0);
1
2
|0|0|0|0|3|4|
|1|2|0|0|0|0|0|3|4|
\link insert(iterator, param_value_type) insert(iterator, value_type)\endlink
[first + max[0, distance(first, last) - (pos - begin()) - reserve()], last)
min[pos - begin(), max[0, distance(first, last) - reserve()]]
[size() + std::distance(first, last)]
min[capacity().%capacity(), size() + std::distance(first, last)]
int array[] = { 5, 6, 7, 8, 9 };
insert(p, array, array + 5);
6
7
8
9
|6|7|8|9|3|4|
|1|2|5|6|7|8|9|3|4|
min[n, (end() - pos) + reserve()]
min[end() - pos, max[0, n - reserve()]]
rinsert(p, (size_t)5, 0);
3
4
|1|2|0|0|0|0|
[first, last - max[0, distance(first, last) - (end() - pos) - reserve()])
min[end() - pos, max[0, distance(first, last) - reserve()]]
5
|1|2|5|6|7|8|
erase(iterator, iterator)
rerase(iterator)
rerase(iterator, iterator)
first == last
erase(iterator)
size() == 0
~circular_buffer_space_optimized()