diff --git a/doc/circular_buffer.html b/doc/circular_buffer.html
index 1c74263..fe8415f 100644
--- a/doc/circular_buffer.html
+++ b/doc/circular_buffer.html
@@ -2367,7 +2367,7 @@ template <class T, class Alloc>
Returns:
- A const reference to the element at the index position.
+ A reference to the element at the index position.
@@ -3607,7 +3607,8 @@ template <class T, class Alloc>
Iterator Invalidation:
-
- Invalidates all iterators pointing to the
circular_buffer.
+ Invalidates all iterators pointing to the circular_buffer if the new capacity is different
+ from the original.
@@ -3710,7 +3711,8 @@ template <class T, class Alloc>
Iterator Invalidation:
-
- Invalidates all iterators pointing to the
circular_buffer.
+ Invalidates all iterators pointing to the circular_buffer if the new size is different
+ from the original.
@@ -3795,7 +3797,8 @@ template <class T, class Alloc>
Iterator Invalidation:
-
- Invalidates all iterators pointing to the
circular_buffer.
+ Invalidates all iterators pointing to the circular_buffer if the new capacity is different
+ from the original.
@@ -3898,7 +3901,8 @@ template <class T, class Alloc>
Iterator Invalidation:
-
- Invalidates all iterators pointing to the
circular_buffer.
+ Invalidates all iterators pointing to the circular_buffer if the new size is different
+ from the original.
@@ -5697,7 +5701,8 @@ template <class T, class Alloc>
Effect:
-
- The elements from the range
[first, last) are removed.
+ The elements from the range [first, last) are removed. (If first == last
+ nothing is removed.)
diff --git a/include/boost/circular_buffer/base.hpp b/include/boost/circular_buffer/base.hpp
index d70e384..2e74ea5 100644
--- a/include/boost/circular_buffer/base.hpp
+++ b/include/boost/circular_buffer/base.hpp
@@ -60,7 +60,7 @@ namespace boost {
http://www.boost.org/libs/circular_buffer/doc/circular_buffer.html
*/
template
-class circular_buffer : cb_details::iterator_registry {
+class circular_buffer : public cb_details::iterator_registry {
// Requirements
BOOST_CLASS_REQUIRE(T, boost, SGIAssignableConcept);
@@ -378,7 +378,7 @@ public:
//! Get the element at the index position.
/*!
\param index The position of the element.
- \return A const reference to the element at the index position.
+ \return A reference to the element at the index position.
\throws std::out_of_range when the index is invalid (when
index >= size()).
\par Complexity
@@ -653,6 +653,9 @@ public:
destroy_item(src);
m_first = m_buff;
m_last = add(m_buff, size());
+#if BOOST_CB_ENABLE_DEBUG
+ invalidate_all_iterators();
+#endif
return m_buff;
}
@@ -760,7 +763,8 @@ public:
\par Exception Safety
Strong.
\par Iterator Invalidation
- Invalidates all iterators pointing to the circular_buffer.
+ Invalidates all iterators pointing to the circular_buffer if the new capacity is different
+ from the original.
\sa rset_capacity(), resize()
*/
void set_capacity(capacity_type new_capacity) {
@@ -768,7 +772,9 @@ public:
return;
pointer buff = allocate(new_capacity);
BOOST_TRY {
- reset(buff, cb_details::uninitialized_copy(begin(), begin() + std::min(new_capacity, size()), buff, m_alloc), new_capacity);
+ reset(buff,
+ cb_details::uninitialized_copy(begin(), begin() + std::min(new_capacity, size()), buff, m_alloc),
+ new_capacity);
} BOOST_CATCH(...) {
deallocate(buff, new_capacity);
BOOST_RETHROW
@@ -796,7 +802,8 @@ public:
\par Exception Safety
Basic.
\par Iterator Invalidation
- Invalidates all iterators pointing to the circular_buffer.
+ Invalidates all iterators pointing to the circular_buffer if the new size is different from
+ the original.
\sa rresize(), set_capacity()
*/
void resize(size_type new_size, param_value_type item = value_type()) {
@@ -823,7 +830,8 @@ public:
\par Exception Safety
Strong.
\par Iterator Invalidation
- Invalidates all iterators pointing to the circular_buffer.
+ Invalidates all iterators pointing to the circular_buffer if the new capacity is different
+ from the original.
\sa set_capacity(), rresize()
*/
void rset_capacity(capacity_type new_capacity) {
@@ -831,7 +839,8 @@ public:
return;
pointer buff = allocate(new_capacity);
BOOST_TRY {
- reset(buff, cb_details::uninitialized_copy(end() - std::min(new_capacity, size()), end(), buff, m_alloc), new_capacity);
+ reset(buff, cb_details::uninitialized_copy(end() - std::min(new_capacity, size()), end(), buff, m_alloc),
+ new_capacity);
} BOOST_CATCH(...) {
deallocate(buff, new_capacity);
BOOST_RETHROW
@@ -851,14 +860,16 @@ public:
\param new_size The new size.
\param item The element the circular_buffer will be filled with in order to gain the requested
size. (See the postcondition.)
- \throws "An allocation error" if memory is exhausted (std::bad_alloc if the standard allocator is used).
+ \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 Complexity
Linear (in the new size of the circular_buffer).
\par Exception Safety
Basic.
\par Iterator Invalidation
- Invalidates all iterators pointing to the circular_buffer.
+ Invalidates all iterators pointing to the circular_buffer if the new size is different from
+ the original.
\sa rresize(), set_capacity()
*/
void rresize(size_type new_size, param_value_type item = value_type()) {
@@ -884,8 +895,7 @@ public:
\note This constructor has been defined only due to compatibility with the STL container definition. Avoid
using it because it allocates very large amount of memory.
*/
- explicit circular_buffer(
- const allocator_type& alloc = allocator_type())
+ explicit circular_buffer(const allocator_type& alloc = allocator_type())
: m_size(0), m_alloc(alloc) {
initialize(max_size());
}
@@ -900,9 +910,7 @@ public:
\par Complexity
Constant.
*/
- explicit circular_buffer(
- capacity_type capacity,
- const allocator_type& alloc = allocator_type())
+ explicit circular_buffer(capacity_type capacity, const allocator_type& alloc = allocator_type())
: m_size(0), m_alloc(alloc) {
initialize(capacity);
}
@@ -920,10 +928,7 @@ public:
\par Complexity
Linear (in the n).
*/
- circular_buffer(
- size_type n,
- param_value_type item,
- const allocator_type& alloc = allocator_type())
+ circular_buffer(size_type n, param_value_type item, const allocator_type& alloc = allocator_type())
: m_size(n), m_alloc(alloc) {
initialize(n, item);
}
@@ -943,10 +948,7 @@ public:
\par Complexity
Linear (in the n).
*/
- circular_buffer(
- capacity_type capacity,
- size_type n,
- param_value_type item,
+ circular_buffer(capacity_type capacity, size_type n, param_value_type item,
const allocator_type& alloc = allocator_type())
: m_size(n), m_alloc(alloc) {
BOOST_CB_ASSERT(capacity >= size()); // check for capacity lower than size
@@ -980,18 +982,13 @@ public:
/*! \cond */
template
- circular_buffer(
- InputIterator first,
- InputIterator last)
+ circular_buffer(InputIterator first, InputIterator last)
: m_alloc(allocator_type()) {
initialize(first, last, is_integral());
}
template
- circular_buffer(
- capacity_type capacity,
- InputIterator first,
- InputIterator last)
+ circular_buffer(capacity_type capacity, InputIterator first, InputIterator last)
: m_alloc(allocator_type()) {
initialize(capacity, first, last, is_integral());
}
@@ -1017,10 +1014,7 @@ public:
Linear (in the std::distance(first, last)).
*/
template
- circular_buffer(
- InputIterator first,
- InputIterator last,
- const allocator_type& alloc = allocator_type())
+ circular_buffer(InputIterator first, InputIterator last, const allocator_type& alloc = allocator_type())
: m_alloc(alloc) {
initialize(first, last, is_integral());
}
@@ -1047,10 +1041,7 @@ public:
Linear (in the capacity/std::distance(first, last)).
*/
template
- circular_buffer(
- capacity_type capacity,
- InputIterator first,
- InputIterator last,
+ circular_buffer(capacity_type capacity, InputIterator first, InputIterator last,
const allocator_type& alloc = allocator_type())
: m_alloc(alloc) {
initialize(capacity, first, last, is_integral());
@@ -1140,8 +1131,8 @@ 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 n copies of the item.
\pre capacity >= n
- \post capacity() == capacity \&\& size() == n \&\& (*this)[0] == item \&\& (*this)[1] == item \&\& ... \&\&
- (*this) [n - 1] == item
+ \post capacity() == capacity \&\& size() == n \&\& (*this)[0] == item \&\& (*this)[1] == item
+ \&\& ... \&\& (*this) [n - 1] == item
\param capacity The new capacity of the circular_buffer.
\param n The number of elements the circular_buffer will be filled with.
\param item The element the circular_buffer will be filled with.
@@ -1396,7 +1387,7 @@ public:
rinsert(iterator, InputIterator, InputIterator)
*/
iterator insert(iterator pos, param_value_type item = value_type()) {
- BOOST_CB_ASSERT(pos.is_valid()); // check for uninitialized or invalidated iterator
+ BOOST_CB_ASSERT(pos.is_valid(this)); // check for uninitialized or invalidated iterator
if (full() && pos == begin())
return begin();
return insert_item(pos, item);
@@ -1436,7 +1427,7 @@ public:
rinsert(iterator, InputIterator, InputIterator)
*/
void insert(iterator pos, size_type n, param_value_type item) {
- BOOST_CB_ASSERT(pos.is_valid()); // check for uninitialized or invalidated iterator
+ BOOST_CB_ASSERT(pos.is_valid(this)); // check for uninitialized or invalidated iterator
if (n == 0)
return;
size_type copy = capacity() - (end() - pos);
@@ -1486,7 +1477,7 @@ public:
*/
template
void insert(iterator pos, InputIterator first, InputIterator last) {
- BOOST_CB_ASSERT(pos.is_valid()); // check for uninitialized or invalidated iterator
+ BOOST_CB_ASSERT(pos.is_valid(this)); // check for uninitialized or invalidated iterator
insert(pos, first, last, is_integral());
}
@@ -1515,7 +1506,7 @@ public:
insert(iterator, InputIterator, InputIterator)
*/
iterator rinsert(iterator pos, param_value_type item = value_type()) {
- BOOST_CB_ASSERT(pos.is_valid()); // check for uninitialized or invalidated iterator
+ BOOST_CB_ASSERT(pos.is_valid(this)); // check for uninitialized or invalidated iterator
if (full() && pos.m_it == 0)
return end();
if (pos == begin()) {
@@ -1592,7 +1583,7 @@ public:
insert(iterator, InputIterator, InputIterator)
*/
void rinsert(iterator pos, size_type n, param_value_type item) {
- BOOST_CB_ASSERT(pos.is_valid()); // check for uninitialized or invalidated iterator
+ BOOST_CB_ASSERT(pos.is_valid(this)); // check for uninitialized or invalidated iterator
rinsert_n(pos, n, cb_details::item_wrapper(item));
}
@@ -1634,7 +1625,7 @@ public:
*/
template
void rinsert(iterator pos, InputIterator first, InputIterator last) {
- BOOST_CB_ASSERT(pos.is_valid()); // check for uninitialized or invalidated iterator
+ BOOST_CB_ASSERT(pos.is_valid(this)); // check for uninitialized or invalidated iterator
rinsert(pos, first, last, is_integral());
}
@@ -1659,8 +1650,8 @@ public:
rerase(iterator, iterator), clear()
*/
iterator erase(iterator pos) {
- BOOST_CB_ASSERT(pos.is_valid()); // check for uninitialized or invalidated iterator
- BOOST_CB_ASSERT(pos.m_it != 0); // check for iterator pointing to end()
+ BOOST_CB_ASSERT(pos.is_valid(this)); // check for uninitialized or invalidated iterator
+ BOOST_CB_ASSERT(pos.m_it != 0); // check for iterator pointing to end()
pointer next = pos.m_it;
increment(next);
for (pointer p = pos.m_it; next != m_last; p = next, increment(next))
@@ -1678,7 +1669,8 @@ public:
//! Erase the range [first, last).
/*!
\pre Valid range [first, last).
- \post The elements from the range [first, last) are removed.
+ \post The elements from the range [first, last) are removed. (If first == last
+ nothing is removed.)
\return Iterator to the first element remaining beyond the removed elements or end() if no such
element exists.
\throws Whatever T::operator = (const T&) throws.
@@ -1693,10 +1685,9 @@ public:
clear()
*/
iterator erase(iterator first, iterator last) {
- BOOST_CB_ASSERT(first.is_valid()); // check for uninitialized or invalidated iterator
- BOOST_CB_ASSERT(last.is_valid()); // check for uninitialized or invalidated iterator
- BOOST_CB_ASSERT(first.m_buff == last.m_buff); // check for iterators of different containers
- BOOST_CB_ASSERT(first <= last); // check for wrong range
+ BOOST_CB_ASSERT(first.is_valid(this)); // check for uninitialized or invalidated iterator
+ BOOST_CB_ASSERT(last.is_valid(this)); // check for uninitialized or invalidated iterator
+ BOOST_CB_ASSERT(first <= last); // check for wrong range
if (first == last)
return first;
pointer p = first.m_it;
@@ -1728,8 +1719,8 @@ public:
rerase(iterator, iterator), clear()
*/
iterator rerase(iterator pos) {
- BOOST_CB_ASSERT(pos.is_valid()); // check for uninitialized or invalidated iterator
- BOOST_CB_ASSERT(pos.m_it != 0); // check for iterator pointing to end()
+ BOOST_CB_ASSERT(pos.is_valid(this)); // check for uninitialized or invalidated iterator
+ BOOST_CB_ASSERT(pos.m_it != 0); // check for iterator pointing to end()
pointer prev = pos.m_it;
pointer p = prev;
for (decrement(prev); p != m_first; p = prev, decrement(prev))
@@ -1762,10 +1753,9 @@ public:
clear()
*/
iterator rerase(iterator first, iterator last) {
- BOOST_CB_ASSERT(first.is_valid()); // check for uninitialized or invalidated iterator
- BOOST_CB_ASSERT(last.is_valid()); // check for uninitialized or invalidated iterator
- BOOST_CB_ASSERT(first.m_buff == last.m_buff); // check for iterators of different containers
- BOOST_CB_ASSERT(first <= last); // check for wrong range
+ BOOST_CB_ASSERT(first.is_valid(this)); // check for uninitialized or invalidated iterator
+ BOOST_CB_ASSERT(last.is_valid(this)); // check for uninitialized or invalidated iterator
+ BOOST_CB_ASSERT(first <= last); // check for wrong range
if (first == last)
return first;
pointer p = map_pointer(last.m_it);
@@ -1906,6 +1896,9 @@ private:
void destroy_content() {
for (size_type ii = 0; ii < size(); ++ii, increment(m_first))
destroy_item(m_first);
+#if BOOST_CB_ENABLE_DEBUG
+ invalidate_iterators(end());
+#endif
}
//! Destroy content and free allocated memory.
@@ -1955,7 +1948,8 @@ private:
//! Specialized initialize method.
template
void initialize(InputIterator first, InputIterator last, const std::input_iterator_tag&) {
- BOOST_CB_ASSERT_TEMPLATED_ITERATOR_CONSTRUCTORS // check if the STL provides templated iterator constructors for containers
+ BOOST_CB_ASSERT_TEMPLATED_ITERATOR_CONSTRUCTORS // check if the STL provides templated iterator constructors
+ // for containers
std::deque tmp(first, last, m_alloc);
size_type distance = tmp.size();
initialize(distance, tmp.begin(), tmp.end(), distance);
@@ -2075,10 +2069,13 @@ private:
//! Specialized assign method.
template
void assign(InputIterator first, InputIterator last, const std::input_iterator_tag&) {
- BOOST_CB_ASSERT_TEMPLATED_ITERATOR_CONSTRUCTORS // check if the STL provides templated iterator constructors for containers
+ BOOST_CB_ASSERT_TEMPLATED_ITERATOR_CONSTRUCTORS // check if the STL provides templated iterator constructors
+ // for containers
std::deque tmp(first, last, m_alloc);
size_type distance = tmp.size();
- assign_n(distance, distance, cb_details::assign_range::iterator, allocator_type>(tmp.begin(), tmp.end(), m_alloc));
+ assign_n(distance, distance,
+ cb_details::assign_range::iterator,
+ allocator_type>(tmp.begin(), tmp.end(), m_alloc));
}
//! Specialized assign method.
@@ -2121,14 +2118,16 @@ private:
//! Specialized assign method.
template
- void assign(capacity_type new_capacity, ForwardIterator first, ForwardIterator last, const std::forward_iterator_tag&) {
+ void assign(capacity_type new_capacity, ForwardIterator first, ForwardIterator last,
+ const std::forward_iterator_tag&) {
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);
distance = new_capacity;
}
- assign_n(new_capacity, distance, cb_details::assign_range(first, last, m_alloc));
+ assign_n(new_capacity, distance,
+ cb_details::assign_range(first, last, m_alloc));
}
//! Helper assign method.
diff --git a/include/boost/circular_buffer/debug.hpp b/include/boost/circular_buffer/debug.hpp
index 71e784c..2a20106 100644
--- a/include/boost/circular_buffer/debug.hpp
+++ b/include/boost/circular_buffer/debug.hpp
@@ -62,7 +62,7 @@ public:
iterator_base& operator = (const iterator_base& rhs);
//! Is the iterator valid?
- bool is_valid() const;
+ bool is_valid(const iterator_registry* registry) const;
//! Invalidate the iterator.
/*!
@@ -184,7 +184,7 @@ inline iterator_base& iterator_base::operator = (const iterator_base& rhs) {
return *this;
}
-inline bool iterator_base::is_valid() const { return m_registry != 0; }
+inline bool iterator_base::is_valid(const iterator_registry* registry) const { return m_registry == registry; }
inline void iterator_base::invalidate() const { m_registry = 0; }
diff --git a/include/boost/circular_buffer/details.hpp b/include/boost/circular_buffer/details.hpp
index afb7127..e33a94b 100644
--- a/include/boost/circular_buffer/details.hpp
+++ b/include/boost/circular_buffer/details.hpp
@@ -264,8 +264,8 @@ public:
//! Dereferencing operator.
reference operator * () const {
- BOOST_CB_ASSERT(is_valid()); // check for uninitialized or invalidated iterator
- BOOST_CB_ASSERT(m_it != 0); // check for iterator pointing to end()
+ BOOST_CB_ASSERT(is_valid(m_buff)); // check for uninitialized or invalidated iterator
+ BOOST_CB_ASSERT(m_it != 0); // check for iterator pointing to end()
return *m_it;
}
@@ -274,9 +274,8 @@ public:
//! Difference operator.
difference_type operator - (const iterator& it) const {
- BOOST_CB_ASSERT(is_valid()); // check for uninitialized or invalidated iterator
- BOOST_CB_ASSERT(it.is_valid()); // check for uninitialized or invalidated iterator
- BOOST_CB_ASSERT(m_buff == it.m_buff); // check for iterators of different containers
+ BOOST_CB_ASSERT(is_valid(m_buff)); // check for uninitialized or invalidated iterator
+ BOOST_CB_ASSERT(it.is_valid(m_buff)); // check for uninitialized or invalidated iterator
helper_pointer lhs = create_helper_pointer(*this);
helper_pointer rhs = create_helper_pointer(it);
if (less(rhs, lhs) && lhs.m_it <= rhs.m_it)
@@ -288,8 +287,8 @@ public:
//! Increment operator (prefix).
iterator& operator ++ () {
- BOOST_CB_ASSERT(is_valid()); // check for uninitialized or invalidated iterator
- BOOST_CB_ASSERT(m_it != 0); // check for iterator pointing to end()
+ BOOST_CB_ASSERT(is_valid(m_buff)); // check for uninitialized or invalidated iterator
+ BOOST_CB_ASSERT(m_it != 0); // check for iterator pointing to end()
m_buff->increment(m_it);
if (m_it == m_buff->m_last)
m_it = 0;
@@ -305,7 +304,7 @@ public:
//! Decrement operator (prefix).
iterator& operator -- () {
- BOOST_CB_ASSERT(is_valid()); // check for uninitialized or invalidated iterator
+ BOOST_CB_ASSERT(is_valid(m_buff)); // check for uninitialized or invalidated iterator
BOOST_CB_ASSERT(m_it != m_buff->m_first); // check for iterator pointing to begin()
if (m_it == 0)
m_it = m_buff->m_last;
@@ -322,7 +321,7 @@ public:
//! Iterator addition.
iterator& operator += (difference_type n) {
- BOOST_CB_ASSERT(is_valid()); // check for uninitialized or invalidated iterator
+ BOOST_CB_ASSERT(is_valid(m_buff)); // check for uninitialized or invalidated iterator
if (n > 0) {
BOOST_CB_ASSERT(m_buff->end() - *this >= n); // check for too large n
m_it = m_buff->add(m_it, n);
@@ -339,7 +338,7 @@ public:
//! Iterator subtraction.
iterator& operator -= (difference_type n) {
- BOOST_CB_ASSERT(is_valid()); // check for uninitialized or invalidated iterator
+ BOOST_CB_ASSERT(is_valid(m_buff)); // check for uninitialized or invalidated iterator
if (n > 0) {
BOOST_CB_ASSERT(m_buff->begin() - *this <= -n); // check for too large n
m_it = m_buff->sub(m_it == 0 ? m_buff->m_last : m_it, n);
@@ -360,27 +359,24 @@ public:
//! Equality.
template
bool operator == (const iterator& it) const {
- BOOST_CB_ASSERT(is_valid()); // check for uninitialized or invalidated iterator
- BOOST_CB_ASSERT(it.is_valid()); // check for uninitialized or invalidated iterator
- BOOST_CB_ASSERT(m_buff == it.m_buff); // check for iterators of different containers
+ BOOST_CB_ASSERT(is_valid(m_buff)); // check for uninitialized or invalidated iterator
+ BOOST_CB_ASSERT(it.is_valid(m_buff)); // check for uninitialized or invalidated iterator
return m_it == it.m_it;
}
//! Inequality.
template
bool operator != (const iterator& it) const {
- BOOST_CB_ASSERT(is_valid()); // check for uninitialized or invalidated iterator
- BOOST_CB_ASSERT(it.is_valid()); // check for uninitialized or invalidated iterator
- BOOST_CB_ASSERT(m_buff == it.m_buff); // check for iterators of different containers
+ BOOST_CB_ASSERT(is_valid(m_buff)); // check for uninitialized or invalidated iterator
+ BOOST_CB_ASSERT(it.is_valid(m_buff)); // check for uninitialized or invalidated iterator
return m_it != it.m_it;
}
//! Less.
template
bool operator < (const iterator& it) const {
- BOOST_CB_ASSERT(is_valid()); // check for uninitialized or invalidated iterator
- BOOST_CB_ASSERT(it.is_valid()); // check for uninitialized or invalidated iterator
- BOOST_CB_ASSERT(m_buff == it.m_buff); // check for iterators of different containers
+ BOOST_CB_ASSERT(is_valid(m_buff)); // check for uninitialized or invalidated iterator
+ BOOST_CB_ASSERT(it.is_valid(m_buff)); // check for uninitialized or invalidated iterator
return less(create_helper_pointer(*this), create_helper_pointer(it));
}
diff --git a/test/base_test.cpp b/test/base_test.cpp
index a5a5430..f0d9b2a 100644
--- a/test/base_test.cpp
+++ b/test/base_test.cpp
@@ -192,59 +192,64 @@ void iterator_comparison_test() {
// TODO add insert, linearize etc.
void iterator_invalidation_test() {
-#if BOOST_CB_ENABLE_DEBUG
+#if !defined(NDEBUG) && !defined(BOOST_CB_DISABLE_DEBUG)
circular_buffer::iterator it1;
circular_buffer::const_iterator it2;
circular_buffer::iterator it3;
circular_buffer::const_iterator it4;
circular_buffer::const_iterator it5;
+ circular_buffer::const_iterator it6;
- BOOST_CHECK(!it1.is_valid());
- BOOST_CHECK(!it2.is_valid());
- BOOST_CHECK(!it3.is_valid());
- BOOST_CHECK(!it4.is_valid());
- BOOST_CHECK(!it5.is_valid());
+ BOOST_CHECK(it1.is_valid(0));
+ BOOST_CHECK(it2.is_valid(0));
+ BOOST_CHECK(it3.is_valid(0));
+ BOOST_CHECK(it4.is_valid(0));
+ BOOST_CHECK(it5.is_valid(0));
+ BOOST_CHECK(it6.is_valid(0));
{
circular_buffer cb(5, 0);
const circular_buffer ccb(5, 0);
it1 = cb.begin();
- it2 = ccb.end();
- it3 = it1;
+ it2 = ccb.begin();
+ it3 = cb.end();
it4 = it1;
it5 = it2;
+ it6 = it1;
- BOOST_CHECK(it1.is_valid());
- BOOST_CHECK(it2.is_valid());
- BOOST_CHECK(it3.is_valid());
- BOOST_CHECK(it4.is_valid());
- BOOST_CHECK(it5.is_valid());
+ BOOST_CHECK(it1.is_valid(&cb));
+ BOOST_CHECK(it2.is_valid(&ccb));
+ BOOST_CHECK(it3.is_valid(&cb));
+ BOOST_CHECK(it4.is_valid(&cb));
+ BOOST_CHECK(it5.is_valid(&ccb));
+ BOOST_CHECK(it6.is_valid(&cb));
}
- BOOST_CHECK(!it1.is_valid());
- BOOST_CHECK(!it2.is_valid());
- BOOST_CHECK(!it3.is_valid());
- BOOST_CHECK(!it4.is_valid());
- BOOST_CHECK(!it5.is_valid());
+ BOOST_CHECK(it1.is_valid(0));
+ BOOST_CHECK(it2.is_valid(0));
+ BOOST_CHECK(it3.is_valid(0));
+ BOOST_CHECK(it4.is_valid(0));
+ BOOST_CHECK(it5.is_valid(0));
+ BOOST_CHECK(it6.is_valid(0));
circular_buffer cb1(10, 0);
circular_buffer cb2(20, 0);
it1 = cb1.end();
it2 = cb2.begin();
- BOOST_CHECK(it1.is_valid());
- BOOST_CHECK(it2.is_valid());
+ BOOST_CHECK(it1.is_valid(&cb1));
+ BOOST_CHECK(it2.is_valid(&cb2));
cb1.swap(cb2);
- BOOST_CHECK(!it1.is_valid());
- BOOST_CHECK(!it2.is_valid());
+ BOOST_CHECK(!it1.is_valid(&cb1));
+ BOOST_CHECK(!it2.is_valid(&cb2));
it1 = cb1.begin() + 3;
it2 = cb1.begin();
cb1.push_back(1);
- BOOST_CHECK(it1.is_valid());
- BOOST_CHECK(!it2.is_valid());
+ BOOST_CHECK(it1.is_valid(&cb1));
+ BOOST_CHECK(!it2.is_valid(&cb1));
BOOST_CHECK(*it2.m_it == 1);
circular_buffer cb3(5);
@@ -256,15 +261,15 @@ void iterator_invalidation_test() {
it1 = cb3.begin() + 2;
it2 = cb3.begin();
cb3.insert(cb3.begin() + 3, 6);
- BOOST_CHECK(it1.is_valid());
- BOOST_CHECK(!it2.is_valid());
+ BOOST_CHECK(it1.is_valid(&cb3));
+ BOOST_CHECK(!it2.is_valid(&cb3));
BOOST_CHECK(*it2.m_it == 5);
it1 = cb3.begin() + 3;
it2 = cb3.end() - 1;
cb3.push_front(7);
- BOOST_CHECK(it1.is_valid());
- BOOST_CHECK(!it2.is_valid());
+ BOOST_CHECK(it1.is_valid(&cb3));
+ BOOST_CHECK(!it2.is_valid(&cb3));
BOOST_CHECK(*it2.m_it == 7);
circular_buffer cb4(5);
@@ -276,53 +281,53 @@ void iterator_invalidation_test() {
it1 = cb4.begin() + 3;
it2 = cb4.begin();
cb4.rinsert(cb4.begin() + 2, 6);
- BOOST_CHECK(it1.is_valid());
- BOOST_CHECK(!it2.is_valid());
+ BOOST_CHECK(it1.is_valid(&cb4));
+ BOOST_CHECK(!it2.is_valid(&cb4));
BOOST_CHECK(*it2.m_it == 2);
it1 = cb1.begin() + 5;
it2 = cb1.end() - 1;
cb1.pop_back();
- BOOST_CHECK(it1.is_valid());
- BOOST_CHECK(!it2.is_valid());
+ BOOST_CHECK(it1.is_valid(&cb1));
+ BOOST_CHECK(!it2.is_valid(&cb1));
it1 = cb1.begin() + 5;
it2 = cb1.begin();
cb1.pop_front();
- BOOST_CHECK(it1.is_valid());
- BOOST_CHECK(!it2.is_valid());
+ BOOST_CHECK(it1.is_valid(&cb1));
+ BOOST_CHECK(!it2.is_valid(&cb1));
circular_buffer cb5(20, 0);
it1 = cb5.begin() + 5;
it2 = it3 = cb5.begin() + 15;
cb5.erase(cb5.begin() + 10);
- BOOST_CHECK(it1.is_valid());
- BOOST_CHECK(!it2.is_valid());
- BOOST_CHECK(!it3.is_valid());
+ BOOST_CHECK(it1.is_valid(&cb5));
+ BOOST_CHECK(!it2.is_valid(&cb5));
+ BOOST_CHECK(!it3.is_valid(&cb5));
it1 = cb5.begin() + 1;
it2 = it3 = cb5.begin() + 8;
cb5.erase(cb5.begin() + 3, cb5.begin() + 7);
- BOOST_CHECK(it1.is_valid());
- BOOST_CHECK(!it2.is_valid());
- BOOST_CHECK(!it3.is_valid());
+ BOOST_CHECK(it1.is_valid(&cb5));
+ BOOST_CHECK(!it2.is_valid(&cb5));
+ BOOST_CHECK(!it3.is_valid(&cb5));
circular_buffer cb6(20, 0);
it4 = it1 = cb6.begin() + 5;
it2 = cb6.begin() + 15;
cb6.rerase(cb6.begin() + 10);
- BOOST_CHECK(!it1.is_valid());
- BOOST_CHECK(!it4.is_valid());
- BOOST_CHECK(it2.is_valid());
+ BOOST_CHECK(!it1.is_valid(&cb6));
+ BOOST_CHECK(!it4.is_valid(&cb6));
+ BOOST_CHECK(it2.is_valid(&cb6));
it4 = it1 = cb6.begin() + 1;
it2 = cb6.begin() + 8;
cb6.rerase(cb6.begin() + 3, cb6.begin() + 7);
- BOOST_CHECK(!it1.is_valid());
- BOOST_CHECK(!it4.is_valid());
- BOOST_CHECK(it2.is_valid());
+ BOOST_CHECK(!it1.is_valid(&cb6));
+ BOOST_CHECK(!it4.is_valid(&cb6));
+ BOOST_CHECK(it2.is_valid(&cb6));
-#endif // #if BOOST_CB_ENABLE_DEBUG
+#endif // #if !defined(NDEBUG) && !defined(BOOST_CB_DISABLE_DEBUG)
}
// basic exception safety test (it is useful to use any memory-leak detection tool)
diff --git a/test/common.ipp b/test/common.ipp
index 408d89f..f0c69dc 100644
--- a/test/common.ipp
+++ b/test/common.ipp
@@ -230,12 +230,12 @@ void element_access_and_insert_test() {
cb.push_back(2);
cb.insert(cb.begin(), 3);
cb.push_back(4);
- const CB_CONTAINER ccb(3, 2);
+ const CB_CONTAINER ccb = cb;
BOOST_CHECK(cb[0] == 1);
BOOST_CHECK(cb[1] == 2);
BOOST_CHECK(cb[2] == 4);
- BOOST_CHECK(ccb[2] == 2);
+ BOOST_CHECK(ccb[2] == 4);
generic_test(cb);
}