RandomAccessIterator + 0

Previously the iterators of boost::container::deque would assert when
zero was added to them in at least the following situations:

- The iterator was obtained by a call to boost::container::deque::begin
  and boost::container::deque::empty returns true
- The iterator was default constructed

This is inconsistent with the way in which the iterators of boost::
container::deque have behaved historically and is also inconsistent
with an understanding of iterators developed by analogy with pointers:

- Adding zero to a null pointer is valid despite the fact the null
  pointer cannot be dereferenced
- Adding zero to a pointer that is one past the end yields a pointer
  which is still one past the end and thus which has well defined
  semantics

Fixed this issue and codified the expected behavior in unit tests.
This commit is contained in:
Robert Leahy
2019-12-22 20:03:57 -05:00
parent 27c1fea452
commit d4a0917821
2 changed files with 52 additions and 0 deletions
+2
View File
@@ -234,6 +234,8 @@ class deque_iterator
deque_iterator& operator+=(difference_type n) BOOST_NOEXCEPT_OR_NOTHROW
{
if (!n)
return *this;
BOOST_ASSERT(!!m_cur);
difference_type offset = n + (this->m_cur - this->m_first);
const difference_type block_size = this->m_last - this->m_first;