diff --git a/doc/circular_buffer.html b/doc/circular_buffer.html index 233f4c8..77a207c 100644 --- a/doc/circular_buffer.html +++ b/doc/circular_buffer.html @@ -4319,7 +4319,8 @@ template <class T, class Alloc> Iterator Invalidation:
circular_buffer.
+ Invalidates all iterators pointing to the circular_buffer (except iterators equal to
+ end()).
The capacity of the circular_buffer will be set to the specified value and the content of
the circular_buffer will be removed and replaced with copies of elements from the specified
- range. (See the Effect.)
+ range.
circular_buffer.
+ Invalidates all iterators pointing to the circular_buffer (except iterators equal to
+ end()).
+ The content of the circular_buffer_space_optimized will be removed and replaced with copies
+ of elements from the specified range.
+
[first, last).first and last have to meet the requirements of InputIterator.
+ 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)
+ first
+ last
+ std::bad_alloc if the standard allocator is
+ used).
+ T::T(const T&) throws.
+ circular_buffer_space_optimized (except
+ iterators equal to end()).
+ std::distance(first, last)).
+ operator=,
+ assign(size_type,
+ const_reference), assign(capacity_type,
+ size_type, const_reference), assign(capacity_type,
+ InputIterator, InputIterator)
+
+ 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.
+
[first, last).first and last have to meet the requirements of InputIterator.
+ capacity() ==
+ capacity_ctrl && size()
+ <= std::distance(first, last) && (*this)[0]== *(last - capacity) && (*this)[1] ==
+ *(last - capacity + 1) && ... && (*this)[capacity - 1] == *(last - 1)[first, last) is greater than the
+ specified capacity then only elements from the range [last - capacity, last)
+ will be copied.max[std::distance(first, last),
+ capacity_ctrl.min_capacity()].
+ capacity_ctrl
+ first
+ last
+ std::bad_alloc if the standard allocator is
+ used).
+ T::T(const T&) throws.
+ circular_buffer_space_optimized (except
+ iterators equal to end()).
+ std::distance(first, last)).
+ operator=,
+ assign(size_type,
+ const_reference), assign(capacity_type,
+ size_type, const_reference), assign(InputIterator,
+ InputIterator)
+ circular_buffer.
+ Invalidates all iterators pointing to the circular_buffer (except iterators equal to end()).
\par Complexity
Linear (in the std::distance(first, last)).
\sa operator=, \link assign(size_type, param_value_type)
@@ -1202,7 +1202,6 @@ public:
/*!
The capacity of the circular_buffer will be set to the specified value and the content of the
circular_buffer will be removed and replaced with copies of elements from the specified range.
- (See the Effect.)
\pre Valid range [first, last).
first and last have to meet the requirements of
InputIterator.
@@ -1221,7 +1220,7 @@ public:
\par Exception Safety
Basic.
\par Iterator Invalidation
- Invalidates all iterators pointing to the circular_buffer.
+ Invalidates all iterators pointing to the circular_buffer (except iterators equal to end()).
\par Complexity
Linear (in the std::distance(first, last)).
\sa operator=, \link assign(size_type, param_value_type)
@@ -2164,7 +2163,7 @@ private:
BOOST_CB_ASSERT(std::distance(first, last) >= 0); // check for wrong range
size_type distance = std::distance(first, last);
if (distance > new_capacity) {
- std::advance(first, distance - capacity);
+ std::advance(first, distance - new_capacity);
distance = new_capacity;
}
assign_n(new_capacity, distance,
diff --git a/include/boost/circular_buffer/space_optimized.hpp b/include/boost/circular_buffer/space_optimized.hpp
index f91da11..90bc3fe 100644
--- a/include/boost/circular_buffer/space_optimized.hpp
+++ b/include/boost/circular_buffer/space_optimized.hpp
@@ -609,7 +609,34 @@ public:
m_capacity_ctrl = capacity_ctrl;
}
- //! See the circular_buffer source documentation.
+ //! 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.
+ \pre Valid range [first, last).
+ first and last have to meet the requirements of
+ InputIterator.
+ \post 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)
+ \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_alloc if the standard allocator is
+ used).
+ \throws Whatever T::T(const T&) throws.
+ \par Exception Safety
+ Basic.
+ \par Iterator Invalidation
+ Invalidates all iterators pointing to the circular_buffer_space_optimized (except iterators
+ equal to end()).
+ \par Complexity
+ Linear (in the std::distance(first, last)).
+ \sa operator=, \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)
+ */
template
void assign(InputIterator first, InputIterator last) {
circular_buffer::assign(first, last);
@@ -617,7 +644,40 @@ public:
m_capacity_ctrl.m_min_capacity = 0;
}
- //! See the circular_buffer source documentation.
+ //! 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.
+ \pre Valid range [first, last).
+ first and last have to meet the requirements of
+ InputIterator.
+ \post 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()].
+ \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_alloc if the standard allocator is
+ used).
+ \throws Whatever T::T(const T&) throws.
+ \par Exception Safety
+ Basic.
+ \par Iterator Invalidation
+ Invalidates all iterators pointing to the circular_buffer_space_optimized (except iterators
+ equal to end()).
+ \par Complexity
+ Linear (in the std::distance(first, last)).
+ \sa operator=, \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)
+ */
template
void assign(capacity_type capacity_ctrl, InputIterator first, InputIterator last) {
m_capacity_ctrl = capacity_ctrl;
diff --git a/test/base_test.cpp b/test/base_test.cpp
index 0b62e3b..ab69060 100644
--- a/test/base_test.cpp
+++ b/test/base_test.cpp
@@ -484,6 +484,28 @@ void iterator_invalidation_test() {
BOOST_CHECK(!it3.is_valid(&cb11));
BOOST_CHECK(!it4.is_valid(&cb11));
+ circular_buffer cb12(10, 1);
+ it1 = cb12.end();
+ it2 = cb12.begin();
+ it3 = cb12.begin() + 3;
+ it4 = cb12.begin() + 7;
+ cb12.assign(cb11.begin(), cb11.end());
+ BOOST_CHECK(it1.is_valid(&cb12));
+ BOOST_CHECK(!it2.is_valid(&cb12));
+ BOOST_CHECK(!it3.is_valid(&cb12));
+ BOOST_CHECK(!it4.is_valid(&cb12));
+
+ circular_buffer cb13(10, 1);
+ it1 = cb13.end();
+ it2 = cb13.begin();
+ it3 = cb13.begin() + 3;
+ it4 = cb13.begin() + 7;
+ cb13.assign(15, cb11.begin(), cb11.end());
+ BOOST_CHECK(it1.is_valid(&cb13));
+ BOOST_CHECK(!it2.is_valid(&cb13));
+ BOOST_CHECK(!it3.is_valid(&cb13));
+ BOOST_CHECK(!it4.is_valid(&cb13));
+
#endif // #if !defined(NDEBUG) && !defined(BOOST_CB_DISABLE_DEBUG)
}