diff --git a/doc/circular_buffer.html b/doc/circular_buffer.html
index b6cd833..1c74263 100644
--- a/doc/circular_buffer.html
+++ b/doc/circular_buffer.html
@@ -226,13 +226,13 @@ public:
bool empty() const;
bool full() const;
size_type reserve() const;
- size_type capacity() const;
+ capacity_type capacity() const;
void set_capacity(size_type new_capacity);
+"#classboost_1_1circular__buffer_161714204ef5172d156e2c7eccd04998f">set_capacity(capacity_type new_capacity);
void resize(size_type new_size, const_reference item = value_type());
void rset_capacity(size_type new_capacity);
+"#classboost_1_1circular__buffer_1477715e9d31d2cc5b02ad8ecf3c68c46">rset_capacity(capacity_type new_capacity);
void rresize(size_type new_size, const_reference item = value_type());
circular_buffer<T, Alloc>& Effect:
capacity() ==
+ capacity() ==
max_size() &&
size() == 0
capacity() ==
+ capacity() ==
capacity && size() == 0
capacity() == n
+ capacity() == n
&& size() == n
&& (*this)[0] == item && (*this)[1] == item && ... && (*this) [n - 1]
== item
@@ -1156,7 +1156,7 @@ template <class T, class Alloc>
Effect:
capacity() ==
+ capacity() ==
capacity && size() == n &&
(*this)[0] == item && (*this)[1] == item && ... && (*this)[n - 1] ==
@@ -1310,7 +1310,7 @@ template <class T, class Alloc>
Effect:
capacity() ==
+ capacity() ==
std::distance(first, last) && size() == std::distance(first,
last) && (*this)[0]== *first && (*this)[1] == *(first + 1) && ... &&
@@ -1401,7 +1401,7 @@ template <class T, class Alloc>
Effect:
capacity() ==
+ capacity() ==
capacity && size() <=
std::distance(first, last) && (*this)[0]== *(last - capacity) && (*this)[1] == *(last -
@@ -2375,8 +2375,8 @@ template <class T, class Alloc>
Throws:
index is invalid (when index >= size()).
+ <code>std::out_of_range</code> when the index is invalid (when index
+ >= size()).
@@ -2450,8 +2450,8 @@ template <class T, class Alloc>
Throws:
index is invalid (when index >= size()).
+ <code>std::out_of_range</code> when the index is invalid (when index
+ >= size()).
@@ -3225,7 +3225,7 @@ template <class T, class Alloc>
capacity(),
+ "#classboost_1_1circular__buffer_15ebab2b2538d733790b5752582728e77">capacity()max_size(),
reserve(),
@@ -3289,7 +3289,7 @@ template <class T, class Alloc>
size(),
capacity(),
+ "#classboost_1_1circular__buffer_15ebab2b2538d733790b5752582728e77">capacity(),
reserve()
capacity() -
+ capacity() -
size()
capacity(),
+ "#classboost_1_1circular__buffer_15ebab2b2538d733790b5752582728e77">capacity(),
size(),
max_size()
size_type capacity()
+ capacity_type capacity()
const;
Get the capacity of the circular_buffer.
@@ -3532,16 +3532,16 @@ template <class T, class Alloc>
max_size(),
set_capacity()
+ "#classboost_1_1circular__buffer_161714204ef5172d156e2c7eccd04998f">set_capacity()
void set_capacity(size_type
+ void set_capacity(capacity_type
new_capacity);
Change the capacity of the circular_buffer.
@@ -3550,7 +3550,7 @@ template <class T, class Alloc>
Effect:
- capacity() ==
+ capacity() ==
new_capacity
If the current number of elements stored in the circular_buffer is greater than the
@@ -3616,7 +3616,7 @@ template <class T, class Alloc>
rset_capacity(),
+ "#classboost_1_1circular__buffer_1477715e9d31d2cc5b02ad8ecf3c68c46">rset_capacity() ,
resize()
@@ -3638,7 +3638,7 @@ template <class T, class Alloc>
size() ==
new_size && capacity() >=
+ "#classboost_1_1circular__buffer_15ebab2b2538d733790b5752582728e77">capacity() >=
new_size
If the new size is greater than the current size, copies of item will be inserted at the
@@ -3720,16 +3720,16 @@ template <class T, class Alloc>
rresize(),
set_capacity()
+ "#classboost_1_1circular__buffer_161714204ef5172d156e2c7eccd04998f">set_capacity()
void rset_capacity(size_type
+ void rset_capacity(capacity_type
new_capacity);
Change the capacity of the circular_buffer.
@@ -3738,7 +3738,7 @@ template <class T, class Alloc>
Effect:
- capacity() ==
+ capacity() ==
new_capacity
If the current number of elements stored in the circular_buffer is greater than the
@@ -3804,7 +3804,7 @@ template <class T, class Alloc>
set_capacity(),
+ "#classboost_1_1circular__buffer_161714204ef5172d156e2c7eccd04998f">set_capacity() ,
rresize()
@@ -3826,7 +3826,7 @@ template <class T, class Alloc>
size() ==
new_size && capacity() >=
+ "#classboost_1_1circular__buffer_15ebab2b2538d733790b5752582728e77">capacity() >=
new_size
If the new size is greater than the current size, copies of item will be inserted at the
@@ -3908,7 +3908,7 @@ template <class T, class Alloc>
rresize(),
set_capacity()
+ "#classboost_1_1circular__buffer_161714204ef5172d156e2c7eccd04998f">set_capacity()
capacity() == n
+ capacity() == n
&& size() == n
&& (*this)[0] == item && (*this)[1] == item && ... && (*this) [n - 1]
== item
@@ -4128,7 +4128,7 @@ template <class T, class Alloc>
Effect:
- capacity() ==
+ capacity() ==
capacity && size() == n &&
(*this)[0] == item && (*this)[1] == item && ... && (*this) [n - 1] ==
@@ -4249,7 +4249,7 @@ template <class T, class Alloc>
Effect:
- capacity() ==
+ capacity() ==
std::distance(first, last) && size() == std::distance(first,
last) && (*this)[0]== *first && (*this)[1] == *(first + 1) && ... &&
@@ -4363,7 +4363,7 @@ template <class T, class Alloc>
Effect:
- capacity() ==
+ capacity() ==
capacity && size() <=
std::distance(first, last) && (*this)[0]== *(last - capacity) && (*this)[1] == *(last -
@@ -4550,7 +4550,7 @@ template <class T, class Alloc>
Effect:
- if capacity()
+ if capacity()
> 0 then back() == item
If the circular_buffer is full, the first element will be removed. If the capacity is
@@ -4632,7 +4632,7 @@ template <class T, class Alloc>
Effect:
- if capacity()
+ if capacity()
> 0 then front() == item
If the circular_buffer is full, the last element will be removed. If the capacity is
@@ -4969,13 +4969,13 @@ template <class T, class Alloc>
Effect:
- The number of min(n, (pos - min[n, (pos - begin()) + reserve()) elements will
+ "#classboost_1_1circular__buffer_10a02c4fbc53385e98569e810be9843de">reserve()] elements will
be inserted at the position pos.
- The number of min(pos - begin(), max(0, n - reserve())) elements
+ The number of min[pos - begin(), max[0, n - reserve()]] elements
will be overwritten at the beginning of the circular_buffer.
(See Example for the explanation.)
@@ -5104,14 +5104,14 @@ template <class T, class Alloc>
Effect:
- Elements from the range [first + max(0, distance(first, last) - (pos - [first + max[0, distance(first, last) - (pos - begin()) - reserve()), last) will
+ "#classboost_1_1circular__buffer_10a02c4fbc53385e98569e810be9843de">reserve()], last) will
be inserted at the position pos.
- The number of min(pos - begin(), max(0, distance(first,
+ The number of min[pos - begin(), max[0, distance(first,
last) - reserve())) elements
+ "#classboost_1_1circular__buffer_10a02c4fbc53385e98569e810be9843de">reserve()]] elements
will be overwritten at the beginning of the circular_buffer.
(See Example for the explanation.)
@@ -5345,13 +5345,13 @@ template <class T, class Alloc>
Effect:
- The number of min(n, (min[n, (end() - pos) + reserve()) elements will
+ "#classboost_1_1circular__buffer_10a02c4fbc53385e98569e810be9843de">reserve()] elements will
be inserted before the position pos.
- The number of min(end() - pos, max(0, n -
- reserve()))
+ The number of min[end() - pos, max[0, n -
+ reserve()]]
elements will be overwritten at the end of the circular_buffer.
(See Example for the explanation.)
@@ -5479,14 +5479,14 @@ template <class T, class Alloc>
Effect:
- Elements from the range [first, last - max(0, distance(first, last) - ([first, last - max[0, distance(first, last) - (end() - pos) - reserve())) will be
+ "#classboost_1_1circular__buffer_10a02c4fbc53385e98569e810be9843de">reserve()]) will be
inserted before the position pos.
- The number of min(end() - pos, max(0,
+ The number of min[end() - pos, max[0,
distance(first, last) - reserve())) elements
+ "#classboost_1_1circular__buffer_10a02c4fbc53385e98569e810be9843de">reserve()]] elements
will be overwritten at the end of the circular_buffer.
(See Example for the explanation.)
diff --git a/doc/circular_buffer_space_optimized.html b/doc/circular_buffer_space_optimized.html
index 4e8e7c9..c3bf0d5 100644
--- a/doc/circular_buffer_space_optimized.html
+++ b/doc/circular_buffer_space_optimized.html
@@ -112,7 +112,7 @@ public:
typedef std::pair<const_pointer, size_type> const_array_range;
typedef implementation-defined capacity_type;
+"#classboost_1_1circular__buffer__space__optimized_1e805212e7de49dcb60f2cad1ef304bb3">capacity_type;
explicit circular_buffer_space_optimized(const allocator_type& alloc = allocator_type());
@@ -187,14 +187,10 @@ public:
bool full() const;
size_type reserve() const;
- size_type min_capacity() const;
+ const capacity_type& capacity() const;
void set_min_capacity(size_type new_min_capacity);
- size_type capacity() const;
- void set_capacity(size_type new_capacity);
+"#classboost_1_1circular__buffer__space__optimized_143fa35280fc3cad2a6510065a065d67c">set_capacity(const capacity_type& new_capacity);
void resize(size_type new_size, const_reference item = value_type());
void
- capacity_type
+ capacity_type
Capacity controller of the space optimized circular buffer.
@@ -423,7 +419,7 @@ template <class T, class Alloc>
(*this).capacity() ==
+ "#classboost_1_1circular__buffer__space__optimized_1aa2695c84ac9fc912e28d1a5920dadfa">capacity() ==
capacity && (*this).size == 0
Allocates memory specified by the min_capacity parameter.
@@ -649,7 +645,7 @@ template <class T, class Alloc>
(*this).capacity() ==
+ "#classboost_1_1circular__buffer__space__optimized_1aa2695c84ac9fc912e28d1a5920dadfa">capacity() ==
capacity
Allocates at least as much memory as specified by the - TODO change min_capacity
parameter.
@@ -723,64 +719,10 @@ template <class T, class Alloc>
- size_type
- min_capacity() const;
-
- Return the minimal guaranteed amount of allocated memory.
-
- The allocated memory will never drop under this value.
-
-
-
-
-
- void
- set_min_capacity(size_type
- new_min_capacity);
-
- Change the minimal guaranteed amount of allocated memory.
-
- -
- Precondition:
-
- -
-
(*this).capacity()
- >= new_min_capacity
-
-
-
- -
- Effect:
-
- -
-
(*this).min_capacity()
- == new_min_capacity Allocates memory specified by the new_min_capacity parameter.
-
-
-
- -
- Note:
-
- -
- It is considered as a bug if the precondition is not met (i.e. if
new_min_capacity >
- (*this).capacity())
- and an assertion will be invoked in the debug mode.
-
-
-
-
-
-
- size_type
+ const
+ capacity_type&
capacity() const;
See the circular_buffer source
@@ -790,22 +732,30 @@ template <class T, class Alloc>
- void
- set_capacity(size_type
+ void
+ set_capacity(const capacity_type&
new_capacity);
- See the circular_buffer source
- documentation.
+ TODO Change the minimal guaranteed amount of allocated memory.
-
Precondition:
-
-
min_capacity()
- <= new_capacity
+ (*this).capacity()
+ >= new_min_capacity
+
+
+
+ -
+ Effect:
+
+ -
+
(*this).min_capacity() == new_min_capacity Allocates memory specified by the
+ new_min_capacity parameter.
@@ -813,11 +763,29 @@ template <class T, class Alloc>
Note:
-
- It is considered as a bug if the precondition is not met (i.e. if
new_capacity > min_capacity())
+ It is considered as a bug if the precondition is not met (i.e. if new_min_capacity >
+ (*this).capacity())
and an assertion will be invoked in the debug mode.
+
+ -
+ Precondition:
+
+ -
+
min_capacity() <= new_capacity
+
+
+
+ -
+ Note:
+
+ -
+ It is considered as a bug if the precondition is not met (i.e. if
new_capacity >
+ min_capacity()) and an assertion will be invoked in the debug mode.
+
+
@@ -850,9 +818,7 @@ template <class T, class Alloc>
Precondition:
- min_capacity()
- <= new_capacity
+ min_capacity() <= new_capacity
@@ -860,9 +826,8 @@ template <class T, class Alloc>
Note:
-
- It is considered as a bug if the precondition is not met (i.e. if
new_capacity > min_capacity())
- and an assertion will be invoked in the debug mode.
+ It is considered as a bug if the precondition is not met (i.e. if new_capacity >
+ min_capacity()) and an assertion will be invoked in the debug mode.
diff --git a/include/boost/circular_buffer/base.hpp b/include/boost/circular_buffer/base.hpp
index 44dc533..fa35928 100644
--- a/include/boost/circular_buffer/base.hpp
+++ b/include/boost/circular_buffer/base.hpp
@@ -379,7 +379,8 @@ public:
/*!
\param index The position of the element.
\return A const reference to the element at the index position.
- \throws std::out_of_range when the index is invalid (when index >= size()).
+ \throws std::out_of_range when the index is invalid (when
+ index >= size()).
\par Complexity
Constant (in the size of the circular_buffer).
\par Exception Safety
@@ -397,7 +398,8 @@ public:
/*!
\param index The position of the element.
\return A const reference to the element at the index position.
- \throws std::out_of_range when the index is invalid (when index >= size()).
+ \throws std::out_of_range when the index is invalid (when
+ index >= size()).
\par Complexity
Constant (in the size of the circular_buffer).
\par Exception Safety
@@ -742,7 +744,7 @@ public:
Does not invalidate any iterators.
\sa reserve(), size(), max_size(), set_capacity()
*/
- size_type capacity() const { return m_end - m_buff; }
+ capacity_type capacity() const { return m_end - m_buff; }
//! Change the capacity of the circular_buffer.
/*!
@@ -761,7 +763,7 @@ public:
Invalidates all iterators pointing to the circular_buffer.
\sa rset_capacity(), resize()
*/
- void set_capacity(size_type new_capacity) {
+ void set_capacity(capacity_type new_capacity) {
if (new_capacity == capacity())
return;
pointer buff = allocate(new_capacity);
@@ -824,7 +826,7 @@ public:
Invalidates all iterators pointing to the circular_buffer.
\sa set_capacity(), rresize()
*/
- void rset_capacity(size_type new_capacity) {
+ void rset_capacity(capacity_type new_capacity) {
if (new_capacity == capacity())
return;
pointer buff = allocate(new_capacity);
@@ -1403,8 +1405,8 @@ public:
//! Insert n copies of the item at the specified position.
/*!
\pre pos is a valid iterator pointing to the circular_buffer or its end.
- \post The number of min(n, (pos - begin()) + reserve()) elements will be inserted at the position
- pos.
The number of min(pos - begin(), max(0, n - reserve())) elements will
+ \post The number of min[n, (pos - begin()) + reserve()] elements will be inserted at the position
+ pos.
The number of min[pos - begin(), max[0, n - reserve()]] elements will
be overwritten at the beginning of the circular_buffer.
(See Example for the
explanation.)
\param pos An iterator specifying the position where the items will be inserted.
@@ -1451,9 +1453,9 @@ public:
Valid range [first, last) where first and last meet 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 position pos.
The number of min(pos - begin(), max(0,
- distance(first, last) - reserve())) elements will be overwritten at the beginning of the
+ [first + max[0, distance(first, last) - (pos - begin()) - reserve()], last) will be
+ inserted at the position pos.
The number of min[pos - begin(), max[0,
+ distance(first, last) - reserve()]] elements will be overwritten at the beginning of the
circular_buffer.
(See Example for the explanation.)
\param pos An iterator specifying the position where the range will be inserted.
\param first The beginning of the range to be inserted.
@@ -1561,8 +1563,8 @@ public:
//! Insert n copies of the item before the specified position.
/*!
\pre pos is a valid iterator pointing to the circular_buffer or its end.
- \post The number of min(n, (end() - pos) + reserve()) elements will be inserted before the
- position pos.
The number of min(end() - pos, max(0, n - reserve())) elements
+ \post The number of min[n, (end() - pos) + reserve()] elements will be inserted before the
+ position pos.
The number of min[end() - pos, max[0, n - reserve()]] elements
will be overwritten at the end of the circular_buffer.
(See Example for the explanation.)
\param pos An iterator specifying the position where the items will be inserted.
\param n The number of items the to be inserted.
@@ -1600,9 +1602,9 @@ public:
Valid range [first, last) where first and last meet 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 position pos.
The number of min(end() - pos, max(0,
- distance(first, last) - reserve())) elements will be overwritten at the end of the
+ [first, last - max[0, distance(first, last) - (end() - pos) - reserve()]) will be inserted
+ before the position pos.
The number of min[end() - pos, max[0,
+ distance(first, last) - reserve()]] elements will be overwritten at the end of the
circular_buffer.
(See Example for the explanation.)
\param pos An iterator specifying the position where the range will be inserted.
\param first The beginning of the range to be inserted.
@@ -2215,10 +2217,10 @@ private:
template
void insert(const iterator& pos, ForwardIterator first, ForwardIterator last, const std::forward_iterator_tag&) {
BOOST_CB_ASSERT(std::distance(first, last) >= 0); // check for wrong range
- difference_type n = std::distance(first, last);
+ size_type n = std::distance(first, last);
if (n == 0)
return;
- difference_type copy = capacity() - (end() - pos);
+ size_type copy = capacity() - (end() - pos);
if (copy == 0)
return;
if (n > copy) {
diff --git a/include/boost/circular_buffer/details.hpp b/include/boost/circular_buffer/details.hpp
index 6f27e7e..46756e8 100644
--- a/include/boost/circular_buffer/details.hpp
+++ b/include/boost/circular_buffer/details.hpp
@@ -77,6 +77,9 @@ struct iterator_wrapper {
mutable Iterator m_it;
explicit iterator_wrapper(Iterator it) : m_it(it) {}
Iterator operator () () const { return m_it++; }
+private:
+ iterator_wrapper(const iterator_wrapper&); // do not generate
+ iterator_wrapper& operator = (const iterator_wrapper&); // do not generate
};
/*!
@@ -88,6 +91,9 @@ struct item_wrapper {
Value m_item;
explicit item_wrapper(Value item) : m_item(item) {}
Pointer operator () () const { return &m_item; }
+private:
+ item_wrapper(const item_wrapper&); // do not generate
+ item_wrapper& operator = (const item_wrapper&); // do not generate
};
/*!
@@ -106,7 +112,8 @@ struct assign_n {
uninitialized_fill_n(p, m_n, m_item, m_alloc);
}
private:
- assign_n& operator = (const assign_n&); // do not generate
+ assign_n(const assign_n&); // do not generate
+ assign_n& operator = (const assign_n&); // do not generate
};
/*!
@@ -124,15 +131,20 @@ struct assign_range {
uninitialized_copy(m_first, m_last, p, m_alloc);
}
private:
- assign_range& operator = (const assign_range&); // do not generate
+ assign_range(const assign_range&); // do not generate
+ assign_range& operator = (const assign_range&); // do not generate
};
/*!
\struct capacity_control
\brief Capacity controller of the space optimized circular buffer.
*/
+#if defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
+template
+#else
template
-struct capacity_control {
+#endif
+class capacity_control {
//! The capacity of the space optimized circular buffer.
Size m_capacity;
@@ -140,6 +152,14 @@ struct capacity_control {
//! The lowest guaranteed capacity of the adapted circular buffer.
Size m_min_capacity;
+#if defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
+ friend circular_buffer_space_optimized;
+#else
+ template friend class circular_buffer_space_optimized;
+#endif
+
+public:
+
//! Constructor.
capacity_control(Size capacity, Size min_capacity = 0)
: m_capacity(capacity), m_min_capacity(min_capacity) {
@@ -149,6 +169,15 @@ struct capacity_control {
// Default copy constructor.
// Default assign operator.
+
+ // Get the capacity of the space optimized circular buffer.
+ Size capacity() const { return m_capacity; }
+
+ // Get the minimal capacity of the space optimized circular buffer.
+ Size min_capacity() const { return m_min_capacity; }
+
+ //! Size operator - returns the capacity of the space optimized circular buffer.
+ operator Size() const { return m_capacity; }
};
/*!
@@ -393,8 +422,6 @@ private:
return lhs.m_it < rhs.m_it;
else if (rdiff == 0)
return rhs.m_end;
- else
- return false;
} else if (ldiff == 0) {
if (rdiff < 0)
return !lhs.m_end;
diff --git a/include/boost/circular_buffer/space_optimized.hpp b/include/boost/circular_buffer/space_optimized.hpp
index 1f61027..9fd6027 100644
--- a/include/boost/circular_buffer/space_optimized.hpp
+++ b/include/boost/circular_buffer/space_optimized.hpp
@@ -37,7 +37,7 @@ namespace boost {
For detailed documentation of the space_optimized_circular_buffer visit:
http://www.boost.org/libs/circular_buffer/doc/circular_buffer_adaptor.html
*/
-template
+template
class circular_buffer_space_optimized : private circular_buffer {
public:
// Typedefs
@@ -59,6 +59,7 @@ public:
typedef typename circular_buffer::param_value_type param_value_type;
typedef typename circular_buffer::return_value_type return_value_type;
+#if defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
//! Capacity controller of the space optimized circular buffer.
/*!
@@ -77,7 +78,12 @@ public:
which ensures compatibility of creating an instance of the
circular_buffer_space_optimized with other STL containers.
*/
+ typedef cb_details::capacity_control capacity_type;
+#else
+ /*! \cond */
typedef cb_details::capacity_control capacity_type;
+ /*! \endcond */
+#endif
// Inherited
@@ -118,32 +124,8 @@ public:
//! See the circular_buffer source documentation.
size_type reserve() const { return capacity() - size(); }
- //! Return the minimal guaranteed amount of allocated memory.
- /*!
- The allocated memory will never drop under this value.
- */
- size_type min_capacity() const { return m_capacity_ctrl.m_min_capacity; }
-
- //! Change the minimal guaranteed amount of allocated memory.
- /*!
- \pre (*this).capacity() >= new_min_capacity
- \post (*this).min_capacity() == new_min_capacity
- Allocates memory specified by the new_min_capacity parameter.
- \note It is considered as a bug if the precondition is not met (i.e. if
- new_min_capacity > (*this).capacity()) and an assertion
- will be invoked in the debug mode.
- */
- void set_min_capacity(size_type new_min_capacity) {
- BOOST_CB_ASSERT(capacity() >= new_min_capacity); // check for too large new min_capacity
- m_capacity_ctrl.m_min_capacity = new_min_capacity;
- if (new_min_capacity > circular_buffer::capacity())
- circular_buffer::set_capacity(new_min_capacity);
- else
- check_high_capacity();
- }
-
//! See the circular_buffer source documentation.
- size_type capacity() const { return m_capacity_ctrl.m_capacity; }
+ const capacity_type& capacity() const { return m_capacity_ctrl; }
#if defined(BOOST_CB_TEST)
@@ -156,18 +138,25 @@ public:
#endif // #if defined(BOOST_CB_TEST)
- //! See the circular_buffer source documentation.
+ //! TODO Change the minimal guaranteed amount of allocated memory.
/*!
+ \pre (*this).capacity() >= new_min_capacity
+ \post (*this).min_capacity() == new_min_capacity
+ Allocates memory specified by the new_min_capacity parameter.
+ \note It is considered as a bug if the precondition is not met (i.e. if
+ new_min_capacity > (*this).capacity()) and an assertion
+ will be invoked in the debug mode.
+
\pre min_capacity() <= new_capacity
\note It is considered as a bug if the precondition is not met (i.e. if
new_capacity > min_capacity()) and an assertion
will be invoked in the debug mode.
*/
- void set_capacity(size_type new_capacity) {
- BOOST_CB_ASSERT(new_capacity >= min_capacity()); // check for too low new capacity
- if (new_capacity < circular_buffer::capacity())
- circular_buffer::set_capacity(new_capacity);
- m_capacity_ctrl.m_capacity = new_capacity;
+ void set_capacity(const capacity_type& new_capacity) {
+ m_capacity_ctrl = new_capacity;
+ if (new_capacity.capacity() < circular_buffer::capacity())
+ circular_buffer::set_capacity(new_capacity.capacity());
+ set_min_capacity(new_capacity.min_capacity());
}
//! See the circular_buffer source documentation.
@@ -188,11 +177,11 @@ public:
new_capacity > min_capacity()) and an assertion
will be invoked in the debug mode.
*/
- void rset_capacity(size_type new_capacity) {
- BOOST_CB_ASSERT(new_capacity >= min_capacity()); // check for too low new capacity
- if (new_capacity < circular_buffer::capacity())
- circular_buffer::rset_capacity(new_capacity);
- m_capacity_ctrl.m_capacity = new_capacity;
+ void rset_capacity(const capacity_type& new_capacity) {
+ m_capacity_ctrl = new_capacity;
+ if (new_capacity.capacity() < circular_buffer::capacity())
+ circular_buffer::rset_capacity(new_capacity.capacity());
+ set_min_capacity(new_capacity.min_capacity());
}
//! See the circular_buffer source documentation.
@@ -575,6 +564,14 @@ public:
private:
// Helper methods
+ //! Change the minimal guaranteed amount of allocated memory.
+ void set_min_capacity(size_type new_min_capacity) {
+ if (new_min_capacity > circular_buffer::capacity())
+ circular_buffer::set_capacity(new_min_capacity);
+ else
+ check_high_capacity();
+ }
+
//! Ensure the reserve for possible growth up.
size_type ensure_reserve(size_type new_capacity, size_type size) const {
if (size + new_capacity / 5 >= new_capacity)
@@ -608,8 +605,8 @@ private:
size_type new_capacity = circular_buffer::capacity();
while (new_capacity / 3 >= size()) { // (new_capacity / 3) -> avoid oscillations
new_capacity /= 2;
- if (new_capacity <= min_capacity()) {
- new_capacity = min_capacity();
+ if (new_capacity <= m_capacity_ctrl.m_min_capacity) {
+ new_capacity = m_capacity_ctrl.m_min_capacity;
break;
}
}
diff --git a/test/common.ipp b/test/common.ipp
index e203dc3..408d89f 100644
--- a/test/common.ipp
+++ b/test/common.ipp
@@ -150,6 +150,8 @@ void allocator_test() {
const CB_CONTAINER cb2(10, 0);
CB_CONTAINER::allocator_type& alloc_ref = cb1.get_allocator();
CB_CONTAINER::allocator_type alloc = cb2.get_allocator();
+ alloc_ref.max_size();
+ alloc.max_size();
generic_test(cb1);
}
diff --git a/test/space_optimized_test.cpp b/test/space_optimized_test.cpp
index fc07920..a82d6ee 100644
--- a/test/space_optimized_test.cpp
+++ b/test/space_optimized_test.cpp
@@ -32,32 +32,32 @@ void min_capacity_test() {
cb_space_optimized cb3(capacity_ctrl(20, 10), v.begin(), v.end());
BOOST_CHECK(cb1.size() == 0);
- BOOST_CHECK(cb1.capacity() == 10);
- BOOST_CHECK(cb1.min_capacity() == 10);
+ BOOST_CHECK(cb1.capacity().capacity() == 10);
+ BOOST_CHECK(cb1.capacity().min_capacity() == 10);
BOOST_CHECK(cb2[0] == 1);
BOOST_CHECK(cb2.size() == 10);
BOOST_CHECK(cb2.capacity() == 10);
- BOOST_CHECK(cb2.min_capacity() == 5);
+ BOOST_CHECK(cb2.capacity().min_capacity() == 5);
BOOST_CHECK(cb3[0] == 1);
BOOST_CHECK(cb3.size() == 5);
BOOST_CHECK(cb3.capacity() == 20);
- BOOST_CHECK(cb3.min_capacity() == 10);
- BOOST_CHECK(cb1.min_capacity() <= cb1.internal_capacity());
- BOOST_CHECK(cb2.min_capacity() <= cb2.internal_capacity());
- BOOST_CHECK(cb3.min_capacity() <= cb3.internal_capacity());
+ BOOST_CHECK(cb3.capacity().min_capacity() == 10);
+ BOOST_CHECK(cb1.capacity().min_capacity() <= cb1.internal_capacity());
+ BOOST_CHECK(cb2.capacity().min_capacity() <= cb2.internal_capacity());
+ BOOST_CHECK(cb3.capacity().min_capacity() <= cb3.internal_capacity());
cb2.erase(cb2.begin() + 2, cb2.end());
BOOST_CHECK(cb2.size() == 2);
- BOOST_CHECK(cb2.min_capacity() <= cb2.internal_capacity());
+ BOOST_CHECK(cb2.capacity().min_capacity() <= cb2.internal_capacity());
cb2.clear();
cb3.clear();
BOOST_CHECK(cb2.empty());
BOOST_CHECK(cb3.empty());
- BOOST_CHECK(cb2.min_capacity() <= cb2.internal_capacity());
- BOOST_CHECK(cb3.min_capacity() <= cb3.internal_capacity());
+ BOOST_CHECK(cb2.capacity().min_capacity() <= cb2.internal_capacity());
+ BOOST_CHECK(cb3.capacity().min_capacity() <= cb3.internal_capacity());
}
// test main