From 4e9f5ebdee3ddbc002835f1ddfc7d973a82296ed Mon Sep 17 00:00:00 2001 From: Eric Niebler Date: Wed, 28 May 2008 00:03:07 +0000 Subject: [PATCH] merged from trunk [SVN r45844] --- doc/circular_buffer.html | 392 ++++++++++-------- doc/space_optimized.html | 245 ++++++----- doc/valid-html40.png | Bin 1444 -> 0 bytes include/boost/circular_buffer/base.hpp | 67 +-- .../boost/circular_buffer/space_optimized.hpp | 9 +- test/common.ipp | 40 +- test/space_optimized_test.cpp | 19 +- 7 files changed, 426 insertions(+), 346 deletions(-) delete mode 100644 doc/valid-html40.png diff --git a/doc/circular_buffer.html b/doc/circular_buffer.html index c96fefc..7e2fda2 100644 --- a/doc/circular_buffer.html +++ b/doc/circular_buffer.html @@ -47,7 +47,8 @@ Standalone Functions
Notes
See also
- Acknowledgements + Acknowledgements
+ Release Notes + + + + + + + + + +
@@ -200,17 +201,17 @@ public: ~circular_buffer(); allocator_type get_allocator() const; +"#classboost_1_1circular__buffer_1a20b7d0e7a4da0af13286df9f53d660c">get_allocator() const; allocator_type& get_allocator(); iterator begin(); iterator end(); - const_iterator begin() const; - const_iterator end() const; + const_iterator begin() const; + const_iterator end() const; reverse_iterator rbegin(); reverse_iterator rend(); const_reverse_iterator rbegin() const; - const_reverse_iterator rend() const; +"#classboost_1_1circular__buffer_1765d91bf48341907418433a1e3aab026">rbegin() const; + const_reverse_iterator rend() const; reference operator[](size_type index); const_reference at(size_type index) const; reference front(); reference back(); - const_reference front() const; - const_reference back() const; + 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; + 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; - capacity_type capacity() const; + size_type size() const; + size_type max_size() const; + bool empty() const; + bool full() const; + size_type reserve() const; + capacity_type capacity() const; void set_capacity(capacity_type new_capacity); void
+ T + + The type of the elements stored in the circular_buffer. +
+
+ Type Requirements: +
+
+ The T has to be SGIAssignable + (SGI STL defined combination of Assignable and CopyConstructible). Moreover T has to be + DefaultConstructible if supplied as + a default parameter when invoking some of the circular_buffer's methods e.g. + insert(iterator pos, const value_type& item = value_type()). And EqualityComparable and/or LessThanComparable if the circular_buffer will + be compared with another container. +
+
+
+
+
+ Alloc + + The allocator type used for all internal memory management. +
+
+ Type Requirements: +
+
+ The Alloc has to meet the allocator requirements imposed by STL. +
+
+
+ std::allocator<T> +

@@ -894,15 +941,15 @@ template <class T, class Alloc> "#classboost_1_1circular__buffer_14e07c6ddfe89debe384e59bed06e7cb7">allocator_type& alloc = allocator_type());

- Create an empty circular_buffer with a maximum capacity. + Create an empty circular_buffer with zero capacity.
Effect:
- capacity() == - max_size() && - size() == 0 + capacity() == 0 + && size() == + 0
@@ -942,9 +989,12 @@ template <class T, class Alloc> Warning:
- This constructor has been defined only due to compatibility with the STL container definition. Avoid - using it because it may allocate very large amount of memory (depending on allocator's - max_size()). + Since Boost version 1.36 the behaviour of this constructor has changed. Now the constructor does not + allocate any memory and both capacity and size are set to zero. Also note when inserting an element + into a circular_buffer with zero capacity (e.g. by push_back(const_reference) + or insert(iterator, + value_type)) nothing will be inserted and the size (as well as capacity) remains zero.
@@ -964,9 +1014,9 @@ template <class T, class Alloc> Effect:
- capacity() == + capacity() == capacity && size() == 0 + "#classboost_1_1circular__buffer_15fa0edd153e2591dd6bf070eb663ee32">size() == 0
@@ -1029,8 +1079,8 @@ template <class T, class Alloc> Effect:
- capacity() == n - && full() + capacity() == n + && full() && (*this)[0] == item && (*this)[1] == item && ... && (*this)[n - 1] == item
@@ -1117,9 +1167,9 @@ template <class T, class Alloc> Effect:
- capacity() == + capacity() == capacity && size() == n && + "#classboost_1_1circular__buffer_15fa0edd153e2591dd6bf070eb663ee32">size() == n && (*this)[0] == item && (*this)[1] == item && ... && (*this)[n - 1] == item
@@ -1271,9 +1321,9 @@ template <class T, class Alloc> Effect:
- capacity() == + capacity() == std::distance(first, last) && full() && (*this)[0]== + "#classboost_1_1circular__buffer_1fd0eef8ba91210d1575404b7e3e8207a">full() && (*this)[0]== *first && (*this)[1] == *(first + 1) && ... && (*this)[std::distance(first, last) - 1] == *(last - 1)
@@ -1362,9 +1412,9 @@ template <class T, class Alloc> Effect:
- capacity() == + capacity() == capacity && size() <= + "#classboost_1_1circular__buffer_15fa0edd153e2591dd6bf070eb663ee32">size() <= std::distance(first, last) && (*this)[0]== *(last - capacity) && (*this)[1] == *(last - capacity + 1) && ... && (*this)[capacity - 1] == *(last - 1)

@@ -1496,8 +1546,8 @@ template <class T, class Alloc> @@ -2407,7 +2457,7 @@ template <class T, class Alloc>
std::out_of_range when the index is invalid (when index >= size()). + "#classboost_1_1circular__buffer_15fa0edd153e2591dd6bf070eb663ee32">size()).
@@ -2577,8 +2627,8 @@ template <class T, class Alloc>
@@ -437,9 +443,9 @@ public:
capacity() == + "#classboost_1_1circular__buffer__space__optimized_1aa2695c84ac9fc912e28d1a5920dadfa">capacity() == capacity_ctrl && size() == + "circular_buffer.html#classboost_1_1circular__buffer_15fa0edd153e2591dd6bf070eb663ee32">size() == 0

The amount of allocated memory in the internal buffer is capacity_ctrl.min_capacity(). @@ -508,9 +514,9 @@ public:
capacity() == + "#classboost_1_1circular__buffer__space__optimized_1aa2695c84ac9fc912e28d1a5920dadfa">capacity() == capacity_ctrl && full() + "#classboost_1_1circular__buffer__space__optimized_142f4a13c50904a4ac0bf746c88451954">full() && (*this)[0] == item && (*this)[1] == item && ... && (*this) [capacity_ctrl.capacity() - 1] == item

@@ -603,9 +609,9 @@ public:
capacity() == + "#classboost_1_1circular__buffer__space__optimized_1aa2695c84ac9fc912e28d1a5920dadfa">capacity() == capacity_ctrl && size() == n + "circular_buffer.html#classboost_1_1circular__buffer_15fa0edd153e2591dd6bf070eb663ee32">size() == n && (*this)[0] == item && (*this)[1] == item && ... && (*this)[n - 1] == item

@@ -765,11 +771,11 @@ public:
capacity().capacity() + "#classboost_1_1circular__buffer__space__optimized_1aa2695c84ac9fc912e28d1a5920dadfa">capacity().capacity() == std::distance(first, last) && capacity().min_capacity() + "#classboost_1_1circular__buffer__space__optimized_1aa2695c84ac9fc912e28d1a5920dadfa">capacity().min_capacity() == 0 && full() + "#classboost_1_1circular__buffer__space__optimized_142f4a13c50904a4ac0bf746c88451954">full() && (*this)[0]== *first && (*this)[1] == *(first + 1) && ... && (*this)[std::distance(first, last) - 1] == *(last - 1)

@@ -862,9 +868,9 @@ public:
capacity() == + "#classboost_1_1circular__buffer__space__optimized_1aa2695c84ac9fc912e28d1a5920dadfa">capacity() == capacity_ctrl && size() + "circular_buffer.html#classboost_1_1circular__buffer_15fa0edd153e2591dd6bf070eb663ee32">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)
@@ -1008,8 +1014,8 @@ public:
- allocator_type get_allocator() const;

@@ -1616,7 +1666,7 @@ template <class T, class Alloc> See Also:
- get_allocator() + get_allocator() const
@@ -1747,8 +1797,8 @@ template <class T, class Alloc>
- const_iterator begin() const;

@@ -1760,7 +1810,7 @@ template <class T, class Alloc>
A const random access iterator pointing to the first element of the circular_buffer. If the circular_buffer is empty it returns an iterator equal to the one returned by - end() + end() const.
@@ -1801,10 +1851,10 @@ template <class T, class Alloc> See Also:
- end() + end() const, rbegin() const, - rend() + "#classboost_1_1circular__buffer_1765d91bf48341907418433a1e3aab026">rbegin() const, + rend() const
@@ -1812,8 +1862,8 @@ template <class T, class Alloc>
- const_iterator end() const;

@@ -1826,7 +1876,7 @@ template <class T, class Alloc> A const random access iterator pointing to the element "one behind" the last element of the circular_buffer. If the circular_buffer is empty it returns an iterator equal to the one returned by begin() const const. + "#classboost_1_1circular__buffer_10640d3d41c13b6089b6f169224cf1038">begin() const
const.
@@ -1866,10 +1916,10 @@ template <class T, class Alloc> See Also:
- begin() + begin() const, rbegin() const, - rend() + "#classboost_1_1circular__buffer_1765d91bf48341907418433a1e3aab026">rbegin() const, + rend() const
@@ -2002,8 +2052,8 @@ template <class T, class Alloc>
- const_reverse_iterator rbegin() const;

@@ -2016,7 +2066,7 @@ template <class T, class Alloc> A const reverse random access iterator pointing to the last element of the circular_buffer. If the circular_buffer is empty it returns an iterator equal to the one returned by rend() const. + "#classboost_1_1circular__buffer_108dbf538b00a14daf5582ece80746fc3">rend() const
.
@@ -2056,10 +2106,10 @@ template <class T, class Alloc> See Also:
- rend() + rend() const, begin() const, - end() + "#classboost_1_1circular__buffer_10640d3d41c13b6089b6f169224cf1038">begin() const, + end() const
@@ -2067,8 +2117,8 @@ template <class T, class Alloc>
- const_reverse_iterator rend() const;

@@ -2081,7 +2131,7 @@ template <class T, class Alloc> A const reverse random access iterator pointing to the element "one before" the first element of the circular_buffer. If the circular_buffer is empty it returns an iterator equal to the one returned by rbegin() const. + "#classboost_1_1circular__buffer_1765d91bf48341907418433a1e3aab026">rbegin() const
.
@@ -2121,10 +2171,10 @@ template <class T, class Alloc> See Also:
- rbegin() + rbegin() const, begin() const, - end() + "#classboost_1_1circular__buffer_10640d3d41c13b6089b6f169224cf1038">begin() const, + end() const
@@ -2144,7 +2194,7 @@ template <class T, class Alloc>
0 <= index && index < size() + "#classboost_1_1circular__buffer_15fa0edd153e2591dd6bf070eb663ee32">size()
@@ -2227,7 +2277,7 @@ template <class T, class Alloc>
0 <= index && index < size() + "#classboost_1_1circular__buffer_15fa0edd153e2591dd6bf070eb663ee32">size()
@@ -2332,7 +2382,7 @@ template <class T, class Alloc>
std::out_of_range when the index is invalid (when index >= size()). + "#classboost_1_1circular__buffer_15fa0edd153e2591dd6bf070eb663ee32">size()).
@@ -2364,7 +2414,7 @@ template <class T, class Alloc> See Also:
- operator[] + operator[]
- const_reference front() const;

@@ -2636,7 +2686,7 @@ template <class T, class Alloc> See Also:
- back() + back() const
@@ -2644,8 +2694,8 @@ template <class T, class Alloc>
- const_reference back() const;

@@ -2703,7 +2753,7 @@ template <class T, class Alloc> See Also:
- front() + front() const
@@ -2910,15 +2960,15 @@ template <class T, class Alloc>
- const_array_range array_one() const;

Get the first continuous array of the internal buffer.

This method in combination with array_two() const can be + "#classboost_1_1circular__buffer_1bb8eb0f298ad2012c55c5303e1f174d5">array_two() const can be useful when passing the stored data into a legacy C API as an array.

@@ -2967,7 +3017,7 @@ template <class T, class Alloc> See Also:
- array_two() + array_two() const; array_one() for more details how to pass data into a legacy C API. @@ -2977,15 +3027,15 @@ template <class T, class Alloc>
- const_array_range array_two() const;

Get the second continuous array of the internal buffer.

This method in combination with array_one() const can be + "#classboost_1_1circular__buffer_10f4b157e27b1170a571417986b239945">array_one() const can be useful when passing the stored data into a legacy C API as an array.

@@ -3035,7 +3085,7 @@ template <class T, class Alloc> See Also:
- array_one() + array_one() const
@@ -3057,7 +3107,7 @@ template <class T, class Alloc>
&(*this)[0] < &(*this)[1] < ... < &(*this)[size() - 1] + "#classboost_1_1circular__buffer_15fa0edd153e2591dd6bf070eb663ee32">size() - 1]
@@ -3132,8 +3182,8 @@ template <class T, class Alloc>
- size_type size() const;

@@ -3184,10 +3234,10 @@ template <class T, class Alloc>
capacity(), + "#classboost_1_1circular__buffer_15ebab2b2538d733790b5752582728e77">capacity(), max_size(), - reserve(), + "#classboost_1_1circular__buffer_157e2d506bc274b2a63fbe1b8fcafebd7">max_size(), + reserve(), resize(size_type, const_reference)
@@ -3196,8 +3246,8 @@ template <class T, class Alloc>
- size_type max_size() const;

@@ -3248,18 +3298,18 @@ template <class T, class Alloc> See Also:
- size(), + size(), capacity(), - reserve() + "#classboost_1_1circular__buffer_15ebab2b2538d733790b5752582728e77">capacity(), + reserve()
- bool empty() + bool empty() const;

Is the circular_buffer empty? @@ -3309,15 +3359,15 @@ template <class T, class Alloc> See Also:
- full() + full()
- bool full() + bool full() const;

Is the circular_buffer full? @@ -3367,15 +3417,15 @@ template <class T, class Alloc> See Also:
- empty() + empty()
- size_type reserve() const;

@@ -3386,8 +3436,8 @@ template <class T, class Alloc> Returns:
- capacity() - - size() + capacity() - + size()
@@ -3428,17 +3478,17 @@ template <class T, class Alloc>
capacity(), - size(), - max_size() + "#classboost_1_1circular__buffer_15ebab2b2538d733790b5752582728e77">capacity(), + size(), + max_size()
- capacity_type capacity() const;

@@ -3488,10 +3538,10 @@ template <class T, class Alloc> See Also:
- reserve(), - size(), + reserve(), + size(), max_size(), + "#classboost_1_1circular__buffer_157e2d506bc274b2a63fbe1b8fcafebd7">max_size(), set_capacity(capacity_type)
@@ -3511,14 +3561,14 @@ template <class T, class Alloc> Effect:
- capacity() == + capacity() == new_capacity && size() <= + "#classboost_1_1circular__buffer_15fa0edd153e2591dd6bf070eb663ee32">size() <= new_capacity

If the current number of elements stored in the circular_buffer is greater than the desired new capacity then number of [size() - new_capacity] + "#classboost_1_1circular__buffer_15fa0edd153e2591dd6bf070eb663ee32">size() - new_capacity]
last elements will be removed and the new size will be equal to new_capacity.
@@ -3573,7 +3623,7 @@ template <class T, class Alloc>
Linear (in min[size(), new_capacity]). + "#classboost_1_1circular__buffer_15fa0edd153e2591dd6bf070eb663ee32">size(), new_capacity]).
@@ -3603,9 +3653,9 @@ template <class T, class Alloc> Effect:
- size() == + 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 @@ -3614,7 +3664,7 @@ template <class T, class Alloc> new_size.
If the current number of elements stored in the circular_buffer is greater than the desired new size then number of [size() - new_size] + "#classboost_1_1circular__buffer_15fa0edd153e2591dd6bf070eb663ee32">size() - new_size]
last elements will be removed. (The capacity will remain unchanged.)
@@ -3709,14 +3759,14 @@ template <class T, class Alloc> Effect:
- capacity() == + capacity() == new_capacity && size() <= + "#classboost_1_1circular__buffer_15fa0edd153e2591dd6bf070eb663ee32">size() <= new_capacity

If the current number of elements stored in the circular_buffer is greater than the desired new capacity then number of [size() - new_capacity] + "#classboost_1_1circular__buffer_15fa0edd153e2591dd6bf070eb663ee32">size() - new_capacity]
first elements will be removed and the new size will be equal to new_capacity.
@@ -3771,7 +3821,7 @@ template <class T, class Alloc>
Linear (in min[size(), new_capacity]). + "#classboost_1_1circular__buffer_15fa0edd153e2591dd6bf070eb663ee32">size(), new_capacity]).
@@ -3801,9 +3851,9 @@ template <class T, class Alloc> Effect:
- size() == + 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 @@ -3812,7 +3862,7 @@ template <class T, class Alloc> new_size.
If the current number of elements stored in the circular_buffer is greater than the desired new size then number of [size() - new_size] + "#classboost_1_1circular__buffer_15fa0edd153e2591dd6bf070eb663ee32">size() - new_size]
first elements will be removed. (The capacity will remain unchanged.)
@@ -3999,8 +4049,8 @@ template <class T, class Alloc> Effect:
- capacity() == n - && size() == n + capacity() == n + && size() == n && (*this)[0] == item && (*this)[1] == item && ... && (*this) [n - 1] == item
@@ -4072,9 +4122,9 @@ template <class T, class Alloc> See Also:
- operator=, - assign(capacity_type, - size_type, const_reference), operator=, assign(capacity_type, size_type, + const_reference), assign(InputIterator, InputIterator), assign(capacity_type, @@ -4111,9 +4161,9 @@ template <class T, class Alloc> Effect:
- capacity() == + capacity() == capacity && size() == n && + "#classboost_1_1circular__buffer_15fa0edd153e2591dd6bf070eb663ee32">size() == n && (*this)[0] == item && (*this)[1] == item && ... && (*this) [n - 1] == item
@@ -4195,8 +4245,8 @@ template <class T, class Alloc> See Also:
- operator=, - assign(size_type, + operator=, assign(size_type, const_reference), assign(InputIterator, InputIterator), Effect:
- capacity() == + capacity() == std::distance(first, last) && size() == std::distance(first, + "#classboost_1_1circular__buffer_15fa0edd153e2591dd6bf070eb663ee32">size() == std::distance(first, last) && (*this)[0]== *first && (*this)[1] == *(first + 1) && ... && (*this)[std::distance(first, last) - 1] == *(last - 1)
@@ -4307,8 +4357,8 @@ template <class T, class Alloc> See Also:
- operator=, - assign(size_type, + operator=, assign(size_type, const_reference), assign(capacity_type, size_type, const_reference), Effect:
- capacity() == + capacity() == capacity && size() <= + "#classboost_1_1circular__buffer_15fa0edd153e2591dd6bf070eb663ee32">size() <= std::distance(first, last) && (*this)[0]== *(last - capacity) && (*this)[1] == *(last - capacity + 1) && ... && (*this)[capacity - 1] == *(last - 1)

@@ -4438,8 +4488,8 @@ template <class T, class Alloc> See Also:
- operator=, - assign(size_type, + operator=, assign(size_type, const_reference), assign(capacity_type, size_type, const_reference), 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 @@ -4621,7 +4671,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 @@ -4978,11 +5028,11 @@ template <class T, class Alloc>
The number of 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 + "#classboost_1_1circular__buffer_10a02c4fbc53385e98569e810be9843de">reserve()]]
elements will be overwritten at the beginning of the circular_buffer.
(See Example for the explanation.)
@@ -5058,7 +5108,7 @@ template <class T, class Alloc>
Linear (in min[capacity(), std::distance(pos, + "#classboost_1_1circular__buffer_15ebab2b2538d733790b5752582728e77">capacity(), std::distance(pos, end()) + n]).
@@ -5132,12 +5182,12 @@ template <class T, class Alloc>
Elements from the range [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, 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.)
@@ -5215,7 +5265,7 @@ template <class T, class Alloc> Linear (in [std::distance(pos, end()) + std::distance(first, last)]; in min[capacity(), std::distance(pos, + "#classboost_1_1circular__buffer_15ebab2b2538d733790b5752582728e77">capacity(), std::distance(pos, end()) + std::distance(first, last)] if the InputIterator is a RandomAccessIterator). @@ -5413,11 +5463,11 @@ template <class T, class Alloc>
The number of 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()]] + reserve()]] elements will be overwritten at the end of the circular_buffer.
(See Example for the explanation.)
@@ -5491,7 +5541,7 @@ template <class T, class Alloc>
Linear (in min[capacity(), + "#classboost_1_1circular__buffer_15ebab2b2538d733790b5752582728e77">capacity(), std::distance(begin(), pos) + n]).
@@ -5566,12 +5616,12 @@ template <class T, class Alloc>
Elements from the range [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, 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.)
@@ -5647,7 +5697,7 @@ template <class T, class Alloc> Linear (in [std::distance(begin(), pos) + std::distance(first, last)]; in min[capacity(), + "#classboost_1_1circular__buffer_15ebab2b2538d733790b5752582728e77">capacity(), std::distance(begin(), pos) + std::distance(first, last)] if the InputIterator is a RandomAccessIterator). @@ -6161,7 +6211,7 @@ template <class T, class Alloc> Effect:
- size() == + size() == 0
@@ -6261,8 +6311,8 @@ template <class T, class Alloc> Returns:
- lhs.size() == - rhs.size() && + lhs.size() == + rhs.size() && std::equal(lhs.begin(), lhs.end(), rhs. +

+ Release Notes +


- - - - - - +

+ Copyright © 2003-2007 Jan Gaspar +

+

+ Use, modification, and distribution is subject to the Boost Software License, Version 1.0.
+ (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+

diff --git a/doc/space_optimized.html b/doc/space_optimized.html index 5716c68..e92b215 100644 --- a/doc/space_optimized.html +++ b/doc/space_optimized.html @@ -35,7 +35,8 @@ Constructors and Destructor
Specific Public Member Functions
See also
- Acknowledgements + Acknowledgements
+ Release Notes

Description

@@ -136,24 +137,24 @@ public: "#classboost_1_1circular__buffer__space__optimized_16839c3ea656ff0f800e38096748fe8ac">~circular_buffer_space_optimized(); allocator_type get_allocator() const; +"circular_buffer.html#classboost_1_1circular__buffer_1a20b7d0e7a4da0af13286df9f53d660c">get_allocator() const; allocator_type& get_allocator(); iterator begin(); iterator end(); const_iterator begin() const; +"circular_buffer.html#classboost_1_1circular__buffer_10640d3d41c13b6089b6f169224cf1038">begin() const; const_iterator end() const; +"circular_buffer.html#classboost_1_1circular__buffer_17890810d07bc595cfb87f9c47cb075ac">end() const; reverse_iterator rbegin(); reverse_iterator rend(); const_reverse_iterator rbegin() const; +"circular_buffer.html#classboost_1_1circular__buffer_1765d91bf48341907418433a1e3aab026">rbegin() const; const_reverse_iterator rend() const; +"circular_buffer.html#classboost_1_1circular__buffer_108dbf538b00a14daf5582ece80746fc3">rend() const; reference operator[](size_type index); const_reference back(); const_reference front() const; +"circular_buffer.html#classboost_1_1circular__buffer_10df8595d83bb9d8a7ce50aabc678f90b">front() const; const_reference back() const; +"circular_buffer.html#classboost_1_1circular__buffer_1027201797868c6274feb6712f670a132">back() const; array_range array_one(); array_range array_two(); const_array_range array_one() const; +"circular_buffer.html#classboost_1_1circular__buffer_10f4b157e27b1170a571417986b239945">array_one() const; const_array_range array_two() const; +"circular_buffer.html#classboost_1_1circular__buffer_1bb8eb0f298ad2012c55c5303e1f174d5">array_two() const; pointer linearize(); size_type size() const; +"circular_buffer.html#classboost_1_1circular__buffer_15fa0edd153e2591dd6bf070eb663ee32">size() const; size_type max_size() const; +"circular_buffer.html#classboost_1_1circular__buffer_157e2d506bc274b2a63fbe1b8fcafebd7">max_size() const; bool empty() const; - bool full() const; +"circular_buffer.html#classboost_1_1circular__buffer_15be1c2a005ec9828549ef6dd7ebed583">empty() const; + bool full() const; size_type reserve() const; +"#classboost_1_1circular__buffer__space__optimized_170eec72a6e8d088b58e26ac7e2dd7c9f">reserve() const; const capacity_type& capacity() const; +"#classboost_1_1circular__buffer__space__optimized_1aa2695c84ac9fc912e28d1a5920dadfa">capacity() const; void set_capacity(const capacity_type& capacity_ctrl); void capacity >= min_capacity
The capacity() + "#classboost_1_1circular__buffer__space__optimized_1aa2695c84ac9fc912e28d1a5920dadfa">capacity() represents the capacity of the circular_buffer_space_optimized and the min_capacity() determines the minimal allocated size of its internal buffer. The converting constructor of the capacity_control allows implicit conversion from @@ -368,23 +369,19 @@ public: "circular_buffer.html#classboost_1_1circular__buffer_14e07c6ddfe89debe384e59bed06e7cb7">allocator_type& alloc = allocator_type());


- Create an empty space optimized circular buffer with a maximum capacity. + Create an empty space optimized circular buffer with zero capacity.
Effect:
capacity().capacity() - == max_size() - && capacity().min_capacity() + "#classboost_1_1circular__buffer__space__optimized_1aa2695c84ac9fc912e28d1a5920dadfa">capacity().capacity() == 0 && size() == - 0
-
- There is no memory allocated in the internal buffer. + "#classboost_1_1circular__buffer__space__optimized_1aa2695c84ac9fc912e28d1a5920dadfa">capacity().min_capacity() + == 0 && size() == + 0
@@ -418,6 +415,15 @@ public: Constant.
+
+
+ Warning: +
+
+ Since Boost version 1.36 the behaviour of this constructor has changed. Now it creates a space + optimized circular buffer with zero capacity. +
+
- bool + bool full() const;

Is the circular_buffer_space_optimized full? @@ -1060,15 +1066,15 @@ public:
empty() + "circular_buffer.html#classboost_1_1circular__buffer_15be1c2a005ec9828549ef6dd7ebed583">empty()
- size_type reserve() const;

@@ -1080,9 +1086,9 @@ public:
capacity().capacity() + "#classboost_1_1circular__buffer__space__optimized_1aa2695c84ac9fc912e28d1a5920dadfa">capacity().capacity() - size() + "circular_buffer.html#classboost_1_1circular__buffer_15fa0edd153e2591dd6bf070eb663ee32">size()
@@ -1123,19 +1129,19 @@ public:
capacity(), + "#classboost_1_1circular__buffer__space__optimized_1aa2695c84ac9fc912e28d1a5920dadfa">capacity(), size(), + "circular_buffer.html#classboost_1_1circular__buffer_15fa0edd153e2591dd6bf070eb663ee32">size(), max_size() + "circular_buffer.html#classboost_1_1circular__buffer_157e2d506bc274b2a63fbe1b8fcafebd7">max_size()
- const + const capacity_type& capacity() const;
@@ -1188,11 +1194,11 @@ public:
reserve(), + "#classboost_1_1circular__buffer__space__optimized_170eec72a6e8d088b58e26ac7e2dd7c9f">reserve(), size(), + "circular_buffer.html#classboost_1_1circular__buffer_15fa0edd153e2591dd6bf070eb663ee32">size(), max_size(), + "circular_buffer.html#classboost_1_1circular__buffer_157e2d506bc274b2a63fbe1b8fcafebd7">max_size(), set_capacity(const capacity_type&) @@ -1216,14 +1222,14 @@ public:
capacity() == + "#classboost_1_1circular__buffer__space__optimized_1aa2695c84ac9fc912e28d1a5920dadfa">capacity() == capacity_ctrl && size() + "circular_buffer.html#classboost_1_1circular__buffer_15fa0edd153e2591dd6bf070eb663ee32">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() - + "circular_buffer.html#classboost_1_1circular__buffer_15fa0edd153e2591dd6bf070eb663ee32">size() - capacity_ctrl.capacity()] last elements will be removed and the new size will be equal to capacity_ctrl.capacity().

@@ -1283,7 +1289,7 @@ public:
Linear (in min[size(), + "circular_buffer.html#classboost_1_1circular__buffer_15fa0edd153e2591dd6bf070eb663ee32">size(), capacity_ctrl.capacity()]).
@@ -1337,9 +1343,9 @@ public:
size() == + "circular_buffer.html#classboost_1_1circular__buffer_15fa0edd153e2591dd6bf070eb663ee32">size() == new_size && capacity().capacity() + "#classboost_1_1circular__buffer__space__optimized_1aa2695c84ac9fc912e28d1a5920dadfa">capacity().capacity() >= new_size

If the new size is greater than the current size, copies of item will be inserted at the @@ -1349,7 +1355,7 @@ public:
If the current number of elements stored in the circular_buffer_space_optimized is greater than the desired new size then number of [size() - + "circular_buffer.html#classboost_1_1circular__buffer_15fa0edd153e2591dd6bf070eb663ee32">size() - new_size] last elements will be removed. (The capacity will remain unchanged.)

The amount of allocated memory in the internal buffer may be accommodated as necessary. @@ -1449,14 +1455,14 @@ public:
capacity() == + "#classboost_1_1circular__buffer__space__optimized_1aa2695c84ac9fc912e28d1a5920dadfa">capacity() == capacity_ctrl && size() + "circular_buffer.html#classboost_1_1circular__buffer_15fa0edd153e2591dd6bf070eb663ee32">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() - + "circular_buffer.html#classboost_1_1circular__buffer_15fa0edd153e2591dd6bf070eb663ee32">size() - capacity_ctrl.capacity()] first elements will be removed and the new size will be equal to capacity_ctrl.capacity().

@@ -1516,7 +1522,7 @@ public:
Linear (in min[size(), + "circular_buffer.html#classboost_1_1circular__buffer_15fa0edd153e2591dd6bf070eb663ee32">size(), capacity_ctrl.capacity()]).
@@ -1551,9 +1557,9 @@ public:
size() == + "circular_buffer.html#classboost_1_1circular__buffer_15fa0edd153e2591dd6bf070eb663ee32">size() == new_size && capacity().capacity() + "#classboost_1_1circular__buffer__space__optimized_1aa2695c84ac9fc912e28d1a5920dadfa">capacity().capacity() >= new_size

If the new size is greater than the current size, copies of item will be inserted at the @@ -1563,7 +1569,7 @@ public:
If the current number of elements stored in the circular_buffer_space_optimized is greater than the desired new size then number of [size() - + "circular_buffer.html#classboost_1_1circular__buffer_15fa0edd153e2591dd6bf070eb663ee32">size() - new_size] first elements will be removed. (The capacity will remain unchanged.)

The amount of allocated memory in the internal buffer may be accommodated as necessary. @@ -1760,11 +1766,11 @@ public:
capacity().capacity() + "#classboost_1_1circular__buffer__space__optimized_1aa2695c84ac9fc912e28d1a5920dadfa">capacity().capacity() == n && capacity().min_capacity() + "#classboost_1_1circular__buffer__space__optimized_1aa2695c84ac9fc912e28d1a5920dadfa">capacity().min_capacity() == 0 && size() == n + "circular_buffer.html#classboost_1_1circular__buffer_15fa0edd153e2591dd6bf070eb663ee32">size() == n && (*this)[0] == item && (*this)[1] == item && ... && (*this) [n - 1] == item

@@ -1839,9 +1845,7 @@ public: See Also:
- operator=, - operator=, assign(capacity_type, size_type, const_reference), assign(InputIterator, @@ -1884,9 +1888,9 @@ public:
capacity() == + "#classboost_1_1circular__buffer__space__optimized_1aa2695c84ac9fc912e28d1a5920dadfa">capacity() == capacity_ctrl && size() == n + "circular_buffer.html#classboost_1_1circular__buffer_15fa0edd153e2591dd6bf070eb663ee32">size() == n && (*this)[0] == item && (*this)[1] == item && ... && (*this) [n - 1] == item

@@ -1971,9 +1975,7 @@ public: See Also:
- operator=, - operator=, assign(size_type, const_reference), assign(InputIterator, @@ -2012,11 +2014,11 @@ public:
capacity().capacity() + "#classboost_1_1circular__buffer__space__optimized_1aa2695c84ac9fc912e28d1a5920dadfa">capacity().capacity() == std::distance(first, last) && capacity().min_capacity() + "#classboost_1_1circular__buffer__space__optimized_1aa2695c84ac9fc912e28d1a5920dadfa">capacity().min_capacity() == 0 && size() == + "circular_buffer.html#classboost_1_1circular__buffer_15fa0edd153e2591dd6bf070eb663ee32">size() == std::distance(first, last) && (*this)[0]== *first && (*this)[1] == *(first + 1) && ... && (*this)[std::distance(first, last) - 1] == *(last - 1)

@@ -2091,9 +2093,7 @@ public: See Also:
- operator=, - operator=, assign(size_type, const_reference), assign(capacity_type, @@ -2135,9 +2135,9 @@ public:
capacity() == + "#classboost_1_1circular__buffer__space__optimized_1aa2695c84ac9fc912e28d1a5920dadfa">capacity() == capacity_ctrl && size() + "circular_buffer.html#classboost_1_1circular__buffer_15fa0edd153e2591dd6bf070eb663ee32">size() <= std::distance(first, last) && (*this)[0]== *(last - capacity) && (*this)[1] == *(last - capacity + 1) && ... && (*this)[capacity - 1] == *(last - 1)

@@ -2229,9 +2229,7 @@ public: See Also:
- operator=, - operator=, assign(size_type, const_reference), assign(capacity_type, @@ -2336,7 +2334,7 @@ public:
if capacity().capacity() + "#classboost_1_1circular__buffer__space__optimized_1aa2695c84ac9fc912e28d1a5920dadfa">capacity().capacity() > 0 then back() == item
@@ -2429,7 +2427,7 @@ public:
if capacity().capacity() + "#classboost_1_1circular__buffer__space__optimized_1aa2695c84ac9fc912e28d1a5920dadfa">capacity().capacity() > 0 then front() == item
@@ -2820,12 +2818,12 @@ public: The number of min[n, (pos - begin()) + reserve()] + "#classboost_1_1circular__buffer__space__optimized_170eec72a6e8d088b58e26ac7e2dd7c9f">reserve()]
elements will be inserted at the position pos.
The number of min[pos - begin(), max[0, n - reserve()]] + "#classboost_1_1circular__buffer__space__optimized_170eec72a6e8d088b58e26ac7e2dd7c9f">reserve()]]
elements will be overwritten at the beginning of the circular_buffer_space_optimized.
(See Example for the explanation.)

@@ -2906,9 +2904,9 @@ public:
Linear (in min[capacity().capacity(), + "#classboost_1_1circular__buffer__space__optimized_1aa2695c84ac9fc912e28d1a5920dadfa">capacity().capacity(), size() + + "circular_buffer.html#classboost_1_1circular__buffer_15fa0edd153e2591dd6bf070eb663ee32">size() + n]).
@@ -2986,12 +2984,12 @@ public: Elements from the range [first + max[0, distance(first, last) - (pos - begin()) - reserve()], + "#classboost_1_1circular__buffer__space__optimized_170eec72a6e8d088b58e26ac7e2dd7c9f">reserve()], last) will be inserted at the position pos.
The number of min[pos - begin(), max[0, distance(first, last) - reserve()]] + "#classboost_1_1circular__buffer__space__optimized_170eec72a6e8d088b58e26ac7e2dd7c9f">reserve()]] elements will be overwritten at the beginning of the circular_buffer_space_optimized.
(See Example for the explanation.)

@@ -3072,11 +3070,11 @@ public:
Linear (in [size() + + "circular_buffer.html#classboost_1_1circular__buffer_15fa0edd153e2591dd6bf070eb663ee32">size() + std::distance(first, last)]; in min[capacity().capacity(), + "#classboost_1_1circular__buffer__space__optimized_1aa2695c84ac9fc912e28d1a5920dadfa">capacity().capacity(), size() + + "circular_buffer.html#classboost_1_1circular__buffer_15fa0edd153e2591dd6bf070eb663ee32">size() + std::distance(first, last)] if the InputIterator is a RandomAccessIterator).
@@ -3291,12 +3289,12 @@ public: The number of min[n, (end() - pos) + reserve()] + "#classboost_1_1circular__buffer__space__optimized_170eec72a6e8d088b58e26ac7e2dd7c9f">reserve()] elements will be inserted before the position pos.
The number of min[end() - pos, max[0, n - reserve()]] + "#classboost_1_1circular__buffer__space__optimized_170eec72a6e8d088b58e26ac7e2dd7c9f">reserve()]] elements will be overwritten at the end of the circular_buffer_space_optimized.
(See Example for the explanation.)

@@ -3377,9 +3375,9 @@ public:
Linear (in min[capacity().capacity(), + "#classboost_1_1circular__buffer__space__optimized_1aa2695c84ac9fc912e28d1a5920dadfa">capacity().capacity(), size() + + "circular_buffer.html#classboost_1_1circular__buffer_15fa0edd153e2591dd6bf070eb663ee32">size() + n]).
@@ -3457,12 +3455,12 @@ public: Elements from the range [first, last - max[0, distance(first, last) - (end() - pos) - reserve()]) + "#classboost_1_1circular__buffer__space__optimized_170eec72a6e8d088b58e26ac7e2dd7c9f">reserve()]) will be inserted before the position pos.
The number of min[end() - pos, max[0, distance(first, last) - reserve()]] + "#classboost_1_1circular__buffer__space__optimized_170eec72a6e8d088b58e26ac7e2dd7c9f">reserve()]] elements will be overwritten at the end of the circular_buffer.
(See Example for the explanation.)
@@ -3544,11 +3542,11 @@ public:
Linear (in [size() + + "circular_buffer.html#classboost_1_1circular__buffer_15fa0edd153e2591dd6bf070eb663ee32">size() + std::distance(first, last)]; in min[capacity().capacity(), + "#classboost_1_1circular__buffer__space__optimized_1aa2695c84ac9fc912e28d1a5920dadfa">capacity().capacity(), size() + + "circular_buffer.html#classboost_1_1circular__buffer_15fa0edd153e2591dd6bf070eb663ee32">size() + std::distance(first, last)] if the InputIterator is a RandomAccessIterator).
@@ -4098,7 +4096,7 @@ public:
size() == + "circular_buffer.html#classboost_1_1circular__buffer_15fa0edd153e2591dd6bf070eb663ee32">size() == 0

The amount of allocated memory in the internal buffer may be predictively decreased. @@ -4175,24 +4173,13 @@ public: The idea of the space optimized circular buffer has been introduced by Pavel Vozenilek.


- - - - - - +

+ Copyright © 2003-2007 Jan Gaspar +

+

+ Use, modification, and distribution is subject to the Boost Software License, Version 1.0.
+ (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+

diff --git a/doc/valid-html40.png b/doc/valid-html40.png deleted file mode 100644 index ba02b4d8530a1a29efdac9ff3a55b7ce316bea20..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1444 zcmeAS@N?(olHy`uVBq!ia0y~yV2EH~V36lvW?*0l5&LzCfq|JJz$e7@|NsBS#>SSG zmR??7X=!OKEiE%=&OCGG%uEJ`G-HOPJ!#d&Y1L`Q&-W((Ka+N5rt#i6UJ?=<|Ns9t z?Aa<1RlW7v^W>$+qUP+Cs9x(eWiLb8%$BX!p1=RTcki*8#%T-;3=Itp{}~t<{xkds zQ~$xN|6oo7NSdJmOf@hxFf=qAIB?*=ode5GefahHDZcZgZWk z+I%qWb==E!+@tD@!NV0eqJ@c(MY@Ta4H=Fs{L94!d zGYn6k4p@`mn_~94M0NEdww3P>Hh*qd%bdTb_!`sqw49_fshgWD^%7*uODErL-79VI z?a1uK)@>JdUu&`HTGaV-z2tRYmqX@QnQ!19%0(K@?z zmh%>sH0MstJO9@)^<(0m)~Q!c%eDx#-@ha2_I=SAlV4BW%&qwqkMd|MZWY;XIsdLC z-=3lf(_76o%DWkreYc(|5L+8GZ&`MEBfHYY!d#BVhxWyt-_s)=e*8MgicRsn-s$Xe z%a#>qFKv6RnHjP>p-BGx29fq$3)4eOcOQ@y-|lR?VQy{zp((qSrW9>m%KvD=v>=ro zJ9OUsDXz?E+cw+%it^frH%ubW9Oe{rS|oPVtvB6hXZZ8N7eCIV+}+NspQ!mMY3ou| zCy$dWgpTggo^cU diff --git a/include/boost/circular_buffer/base.hpp b/include/boost/circular_buffer/base.hpp index 8088bae..8bc0a80 100644 --- a/include/boost/circular_buffer/base.hpp +++ b/include/boost/circular_buffer/base.hpp @@ -907,22 +907,23 @@ public: // Construction/Destruction - //! Create an empty circular_buffer with a maximum capacity. + //! Create an empty circular_buffer with zero capacity. /*! - \post capacity() == max_size() \&\& size() == 0 + \post capacity() == 0 \&\& size() == 0 \param alloc The allocator. \throws "An allocation error" if memory is exhausted (std::bad_alloc if the standard allocator is used). \par Complexity Constant. - \warning This constructor has been defined only due to compatibility with the STL container definition. Avoid - using it because it may allocate very large amount of memory (depending on allocator's - %max_size()). + \warning Since Boost version 1.36 the behaviour of this constructor has changed. Now the constructor does not + allocate any memory and both capacity and size are set to zero. Also note when inserting an element + into a circular_buffer with zero capacity (e.g. by + \link push_back() push_back(const_reference)\endlink or + \link insert(iterator, param_value_type) insert(iterator, value_type)\endlink) nothing + will be inserted and the size (as well as capacity) remains zero. */ explicit circular_buffer(const allocator_type& alloc = allocator_type()) - : m_size(0), m_alloc(alloc) { - initialize(max_size()); - } + : m_buff(0), m_end(0), m_first(0), m_last(0), m_size(0), m_alloc(alloc) {} //! Create an empty circular_buffer with the specified capacity. /*! @@ -936,7 +937,8 @@ public: */ explicit circular_buffer(capacity_type capacity, const allocator_type& alloc = allocator_type()) : m_size(0), m_alloc(alloc) { - initialize(capacity); + initialize_buffer(capacity); + m_first = m_last = m_buff; } /*! \brief Create a full circular_buffer with the specified capacity and filled with n @@ -954,7 +956,8 @@ public: */ circular_buffer(size_type n, param_value_type item, const allocator_type& alloc = allocator_type()) : m_size(n), m_alloc(alloc) { - initialize(n, item); + initialize_buffer(n, item); + m_first = m_last = m_buff; } /*! \brief Create a circular_buffer with the specified capacity and filled with n @@ -976,7 +979,9 @@ public: const allocator_type& alloc = allocator_type()) : m_size(n), m_alloc(alloc) { BOOST_CB_ASSERT(capacity >= size()); // check for capacity lower than size - initialize(capacity, item); + initialize_buffer(capacity, item); + m_first = m_buff; + m_last = capacity == n ? m_buff : m_buff + n; } //! The copy constructor. @@ -992,14 +997,17 @@ public: */ circular_buffer(const circular_buffer& cb) : m_size(cb.size()), m_alloc(cb.get_allocator()) { - m_first = m_last = m_buff = allocate(cb.capacity()); + initialize_buffer(cb.capacity()); + m_first = m_buff; BOOST_TRY { - m_end = cb_details::uninitialized_copy_with_alloc(cb.begin(), cb.end(), m_buff, m_alloc); + m_last = cb_details::uninitialized_copy_with_alloc(cb.begin(), cb.end(), m_buff, m_alloc); } BOOST_CATCH(...) { deallocate(m_buff, cb.capacity()); BOOST_RETHROW } BOOST_CATCH_END + if (m_last == m_end) + m_last = m_buff; } #if BOOST_WORKAROUND(BOOST_MSVC, < 1300) @@ -1997,15 +2005,15 @@ private: #endif } - //! Initialize the circular buffer. - void initialize(capacity_type capacity) { - m_first = m_last = m_buff = allocate(capacity); + //! Initialize the internal buffer. + void initialize_buffer(capacity_type capacity) { + m_buff = allocate(capacity); m_end = m_buff + capacity; } - //! Initialize the circular buffer. - void initialize(capacity_type capacity, param_value_type item) { - initialize(capacity); + //! Initialize the internal buffer. + void initialize_buffer(capacity_type capacity, param_value_type item) { + initialize_buffer(capacity); BOOST_TRY { cb_details::uninitialized_fill_n_with_alloc(m_buff, size(), item, m_alloc); } BOOST_CATCH(...) { @@ -2019,7 +2027,8 @@ private: template void initialize(IntegralType n, IntegralType item, const true_type&) { m_size = static_cast(n); - initialize(size(), item); + initialize_buffer(size(), item); + m_first = m_last = m_buff; } //! Specialized initialize method. @@ -2056,7 +2065,9 @@ private: void initialize(capacity_type capacity, IntegralType n, IntegralType item, const true_type&) { BOOST_CB_ASSERT(capacity >= static_cast(n)); // check for capacity lower than n m_size = static_cast(n); - initialize(capacity, item); + initialize_buffer(capacity, item); + m_first = m_buff; + m_last = capacity == size() ? m_buff : m_buff + size(); } //! Specialized initialize method. @@ -2076,7 +2087,8 @@ private: InputIterator first, InputIterator last, const std::input_iterator_tag&) { - initialize(capacity); + initialize_buffer(capacity); + m_first = m_last = m_buff; m_size = 0; if (capacity == 0) return; @@ -2102,28 +2114,29 @@ private: initialize(capacity, first, last, std::distance(first, last)); } - //! Helper initialize method. + //! Initialize the circular buffer. template void initialize(capacity_type capacity, ForwardIterator first, ForwardIterator last, size_type distance) { - initialize(capacity); + initialize_buffer(capacity); + m_first = m_buff; if (distance > capacity) { std::advance(first, distance - capacity); m_size = capacity; } else { m_size = distance; - if (distance != capacity) - m_last = m_buff + size(); } BOOST_TRY { - cb_details::uninitialized_copy_with_alloc(first, last, m_buff, m_alloc); + m_last = cb_details::uninitialized_copy_with_alloc(first, last, m_buff, m_alloc); } BOOST_CATCH(...) { deallocate(m_buff, capacity); BOOST_RETHROW } BOOST_CATCH_END + if (m_last == m_end) + m_last = m_buff; } //! Reset the circular buffer. diff --git a/include/boost/circular_buffer/space_optimized.hpp b/include/boost/circular_buffer/space_optimized.hpp index 4684552..c1b90ee 100644 --- a/include/boost/circular_buffer/space_optimized.hpp +++ b/include/boost/circular_buffer/space_optimized.hpp @@ -312,18 +312,19 @@ public: } } - //! Create an empty space optimized circular buffer with a maximum capacity. + //! Create an empty space optimized circular buffer with zero capacity. /*! - \post capacity().%capacity() == max_size() \&\& capacity().min_capacity() == 0 \&\& size() == 0 -

There is no memory allocated in the internal buffer. + \post capacity().%capacity() == 0 \&\& capacity().min_capacity() == 0 \&\& size() == 0 \param alloc The allocator. \throws Nothing. \par Complexity Constant. + \warning Since Boost version 1.36 the behaviour of this constructor has changed. Now it creates a space + optimized circular buffer with zero capacity. */ explicit circular_buffer_space_optimized(const allocator_type& alloc = allocator_type()) : circular_buffer(0, alloc) - , m_capacity_ctrl(max_size()) {} + , m_capacity_ctrl(0) {} //! Create an empty space optimized circular buffer with the specified capacity. /*! diff --git a/test/common.ipp b/test/common.ipp index d3403f7..7ef1f6d 100644 --- a/test/common.ipp +++ b/test/common.ipp @@ -769,6 +769,17 @@ void rresize_test() { void constructor_test() { + CB_CONTAINER cb0; + BOOST_CHECK(cb0.capacity() == 0); + BOOST_CHECK(cb0.size() == 0); + + cb0.push_back(1); + cb0.push_back(2); + cb0.push_back(3); + + BOOST_CHECK(cb0.size() == 0); + BOOST_CHECK(cb0.capacity() == 0); + CB_CONTAINER cb1(3); CB_CONTAINER cb2(3, 2); vector v; @@ -780,6 +791,7 @@ void constructor_test() { CB_CONTAINER cb3(v.begin(), v.end()); CB_CONTAINER cb4(3, v.begin(), v.end()); CB_CONTAINER cb5(10, v.begin(), v.end()); + CB_CONTAINER cb6(10, 3, MyInteger(2)); BOOST_CHECK(cb1.size() == 0); BOOST_CHECK(cb1.capacity() == 3); @@ -803,19 +815,29 @@ void constructor_test() { BOOST_CHECK(!cb5.full()); BOOST_CHECK(cb5[0] == 1); BOOST_CHECK(cb5[4] == 5); + BOOST_CHECK(cb6.size() == 3); + BOOST_CHECK(cb6.capacity() == 10); + BOOST_CHECK(!cb6.full()); + BOOST_CHECK(cb6[0] == 2); + BOOST_CHECK(cb6[2] == 2); cb5.push_back(6); + cb6.push_back(6); BOOST_CHECK(cb5[5] == 6); + BOOST_CHECK(cb5[0] == 1); BOOST_CHECK(cb5.size() == 6); + BOOST_CHECK(cb6[3] == 6); + BOOST_CHECK(cb6.size() == 4); + BOOST_CHECK(cb6[0] == 2); #if !defined(BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS) - CB_CONTAINER cb6(MyInputIterator(v.begin()), MyInputIterator(v.end())); - CB_CONTAINER cb7(3, MyInputIterator(v.begin()), MyInputIterator(v.end())); + CB_CONTAINER cb7(MyInputIterator(v.begin()), MyInputIterator(v.end())); + CB_CONTAINER cb8(3, MyInputIterator(v.begin()), MyInputIterator(v.end())); - BOOST_CHECK(cb6.capacity() == 5); - BOOST_CHECK(cb7.capacity() == 3); + BOOST_CHECK(cb7.capacity() == 5); + BOOST_CHECK(cb8.capacity() == 3); #endif // #if !defined(BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS) @@ -824,6 +846,7 @@ void constructor_test() { generic_test(cb3); generic_test(cb4); generic_test(cb5); + generic_test(cb6); } void assign_test() { @@ -894,6 +917,9 @@ void copy_constructor_and_assign_test() { CB_CONTAINER cb2 = cb1; BOOST_CHECK(cb1 == cb2); + BOOST_CHECK(cb2.capacity() == 4); + BOOST_CHECK(cb2[0] == 2); + BOOST_CHECK(cb2[3] == 5); CB_CONTAINER cb3(20); cb1.pop_back(); @@ -901,6 +927,7 @@ void copy_constructor_and_assign_test() { cb3 = cb2; cb3 = cb3; cb4 = cb1; + CB_CONTAINER cb5 = cb1; BOOST_CHECK(cb3 == cb2); BOOST_CHECK(cb4 == cb1); @@ -911,11 +938,16 @@ void copy_constructor_and_assign_test() { BOOST_CHECK(cb4.capacity() == 4); BOOST_CHECK(!cb4.full()); BOOST_CHECK(*(cb4.end() - 1) == 4); + BOOST_CHECK(cb1 == cb5); + BOOST_CHECK(cb5.capacity() == 4); + BOOST_CHECK(cb2[0] == 2); + BOOST_CHECK(cb2[2] == 4); generic_test(cb1); generic_test(cb2); generic_test(cb3); generic_test(cb4); + generic_test(cb5); } void swap_test() { diff --git a/test/space_optimized_test.cpp b/test/space_optimized_test.cpp index b0c7884..c05a8b0 100644 --- a/test/space_optimized_test.cpp +++ b/test/space_optimized_test.cpp @@ -62,7 +62,7 @@ void capacity_control_test() { circular_buffer_space_optimized::capacity_type c1 = 10; circular_buffer_space_optimized::capacity_type c2 = - circular_buffer_space_optimized::capacity_type(20, 5); + circular_buffer_space_optimized::capacity_type(20, 5); circular_buffer_space_optimized::capacity_type c3 = c2; BOOST_CHECK(c1.capacity() == 10); @@ -78,10 +78,10 @@ void capacity_control_test() { BOOST_CHECK(c1.min_capacity() == 5); } -void some_constructors_test() { +void specific_constructors_test() { cb_space_optimized cb1; - BOOST_CHECK(cb1.capacity() == cb1.max_size()); + BOOST_CHECK(cb1.capacity() == 0); BOOST_CHECK(cb1.capacity().min_capacity() == 0); BOOST_CHECK(cb1.internal_capacity() == 0); BOOST_CHECK(cb1.size() == 0); @@ -90,10 +90,15 @@ void some_constructors_test() { cb1.push_back(2); cb1.push_back(3); - BOOST_CHECK(cb1.size() == 3); - BOOST_CHECK(cb1.capacity() == cb1.max_size()); + BOOST_CHECK(cb1.size() == 0); + BOOST_CHECK(cb1.capacity() == 0); - cb_space_optimized cb2(cb1.begin(), cb1.end()); + vector v; + v.push_back(1); + v.push_back(2); + v.push_back(3); + + cb_space_optimized cb2(v.begin(), v.end()); BOOST_CHECK(cb2.capacity() == 3); BOOST_CHECK(cb2.capacity().min_capacity() == 0); @@ -183,7 +188,7 @@ test_suite* init_unit_test_suite(int /*argc*/, char* /*argv*/[]) { tests->add(BOOST_TEST_CASE(&min_capacity_test)); tests->add(BOOST_TEST_CASE(&capacity_control_test)); - tests->add(BOOST_TEST_CASE(&some_constructors_test)); + tests->add(BOOST_TEST_CASE(&specific_constructors_test)); tests->add(BOOST_TEST_CASE(&shrink_to_fit_test)); tests->add(BOOST_TEST_CASE(&iterator_invalidation_test));