From 0fee9038df2988ef56c6dbc09e15c7b2fd12f1f9 Mon Sep 17 00:00:00 2001 From: Jan Gaspar Date: Mon, 16 Apr 2007 23:19:07 +0000 Subject: [PATCH] circular_buffer: updated srcdoc + assign bug fix [SVN r3976] --- doc/circular_buffer.html | 8 +- doc/circular_buffer_space_optimized.html | 240 +++++++++++++++++- include/boost/circular_buffer/base.hpp | 7 +- .../boost/circular_buffer/space_optimized.hpp | 64 ++++- test/base_test.cpp | 22 ++ 5 files changed, 326 insertions(+), 15 deletions(-) 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:
- Invalidates all iterators pointing to the circular_buffer. + Invalidates all iterators pointing to the circular_buffer (except iterators equal to + end()).
@@ -4359,7 +4360,7 @@ template <class T, class Alloc>

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.

@@ -4447,7 +4448,8 @@ template <class T, class Alloc> Iterator Invalidation:
- Invalidates all iterators pointing to the circular_buffer. + Invalidates all iterators pointing to the circular_buffer (except iterators equal to + end()).
diff --git a/doc/circular_buffer_space_optimized.html b/doc/circular_buffer_space_optimized.html index 0af5485..910ba58 100644 --- a/doc/circular_buffer_space_optimized.html +++ b/doc/circular_buffer_space_optimized.html @@ -1956,9 +1956,115 @@ public: <class InputIterator>
void assign(InputIterator first, InputIterator last);

- 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. +

+
+
+ 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) +
+
@@ -1970,9 +2076,131 @@ public: "#classboost_1_1circular__buffer__space__optimized_1e805212e7de49dcb60f2cad1ef304bb3">capacity_type capacity_ctrl, InputIterator first, InputIterator last);

- 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. +

+
+
+ 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) +
+
diff --git a/include/boost/circular_buffer/base.hpp b/include/boost/circular_buffer/base.hpp index 02ff60f..2c1d32b 100644 --- a/include/boost/circular_buffer/base.hpp +++ b/include/boost/circular_buffer/base.hpp @@ -1184,7 +1184,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) @@ -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) }