Fix off-by-one bug in wxVector::reverse_iterator::base()
This is embarrassing, but the iterator returned by this method seems to have always been wrong, ever since it was added back in946954d3bf
(Added reverse iterator to wxVector<T>, 2008-09-16). Moreover, it was also broken in its const_reverse_iterator counterpart where it was copy-and-pasted inf7ef20685f
(Add wxVector<>::const_reverse_iterator, 2013-05-08). Finally fix this to return the correct value and add at least a simple unit test check that this method behaves as expected.
This commit is contained in:
@@ -198,7 +198,7 @@ public:
|
|||||||
reference operator*() const { return *m_ptr; }
|
reference operator*() const { return *m_ptr; }
|
||||||
pointer operator->() const { return m_ptr; }
|
pointer operator->() const { return m_ptr; }
|
||||||
|
|
||||||
iterator base() const { return m_ptr; }
|
iterator base() const { return m_ptr + 1; }
|
||||||
|
|
||||||
reverse_iterator& operator++()
|
reverse_iterator& operator++()
|
||||||
{ --m_ptr; return *this; }
|
{ --m_ptr; return *this; }
|
||||||
@@ -261,7 +261,7 @@ public:
|
|||||||
const_reference operator*() const { return *m_ptr; }
|
const_reference operator*() const { return *m_ptr; }
|
||||||
const_pointer operator->() const { return m_ptr; }
|
const_pointer operator->() const { return m_ptr; }
|
||||||
|
|
||||||
const_iterator base() const { return m_ptr; }
|
const_iterator base() const { return m_ptr + 1; }
|
||||||
|
|
||||||
const_reverse_iterator& operator++()
|
const_reverse_iterator& operator++()
|
||||||
{ --m_ptr; return *this; }
|
{ --m_ptr; return *this; }
|
||||||
|
@@ -334,6 +334,10 @@ TEST_CASE("wxVector::reverse_iterator", "[vector][reverse_iterator]")
|
|||||||
CHECK( ri < re );
|
CHECK( ri < re );
|
||||||
CHECK( ri <= re );
|
CHECK( ri <= re );
|
||||||
|
|
||||||
|
CHECK( rb.base() == v.end() );
|
||||||
|
CHECK( re.base() == v.begin() );
|
||||||
|
CHECK( *ri.base() == 9 );
|
||||||
|
|
||||||
#if wxUSE_STD_CONTAINERS_COMPATIBLY
|
#if wxUSE_STD_CONTAINERS_COMPATIBLY
|
||||||
std::vector<int> stdvec(rb, re);
|
std::vector<int> stdvec(rb, re);
|
||||||
REQUIRE( stdvec.size() == 10 );
|
REQUIRE( stdvec.size() == 10 );
|
||||||
|
Reference in New Issue
Block a user