Make wxVector::reverse_iterator satisfy RandomAccessIterator

RandomAccessIterator requirements include LessThanComparable, so
implement the missing comparison operators for this class, as well as
for const_reverse_iterator.

This also fixes compilation problems with MSVS 2013 in debug mode, where
the CRT uses these operators to check the iterators correctness.

See https://github.com/wxWidgets/wxWidgets/pull/1048
This commit is contained in:
Vadim Zeitlin
2018-12-07 14:52:51 +01:00
parent 3d75541662
commit aee926f2d5
2 changed files with 23 additions and 0 deletions

View File

@@ -219,6 +219,14 @@ public:
{ return m_ptr == it.m_ptr; }
bool operator !=(const reverse_iterator& it) const
{ return m_ptr != it.m_ptr; }
bool operator<(const reverse_iterator& it) const
{ return m_ptr > it.m_ptr; }
bool operator>(const reverse_iterator& it) const
{ return m_ptr < it.m_ptr; }
bool operator<=(const reverse_iterator& it) const
{ return m_ptr >= it.m_ptr; }
bool operator>=(const reverse_iterator& it) const
{ return m_ptr <= it.m_ptr; }
private:
value_type *m_ptr;
@@ -274,6 +282,14 @@ public:
{ return m_ptr == it.m_ptr; }
bool operator !=(const const_reverse_iterator& it) const
{ return m_ptr != it.m_ptr; }
bool operator<(const const_reverse_iterator& it) const
{ return m_ptr > it.m_ptr; }
bool operator>(const const_reverse_iterator& it) const
{ return m_ptr < it.m_ptr; }
bool operator<=(const const_reverse_iterator& it) const
{ return m_ptr >= it.m_ptr; }
bool operator>=(const const_reverse_iterator& it) const
{ return m_ptr <= it.m_ptr; }
protected:
const value_type *m_ptr;

View File

@@ -365,6 +365,13 @@ TEST_CASE("wxVector::reverse_iterator", "[vector][reverse_iterator]")
CHECK( ri - rb == 2 );
CHECK( re - ri == 8 );
CHECK( rb < ri );
CHECK( rb <= ri );
CHECK( ri <= ri );
CHECK( ri >= ri );
CHECK( ri < re );
CHECK( ri <= re );
#if wxUSE_STD_CONTAINERS_COMPATIBLY
std::vector<int> stdvec(rb, re);
REQUIRE( stdvec.size() == 10 );