From aee926f2d54b40db8f66217a7b69074f0d86bfcd Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 7 Dec 2018 14:52:51 +0100 Subject: [PATCH] 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 --- include/wx/vector.h | 16 ++++++++++++++++ tests/vectors/vectors.cpp | 7 +++++++ 2 files changed, 23 insertions(+) diff --git a/include/wx/vector.h b/include/wx/vector.h index 113157875c..25067081b4 100644 --- a/include/wx/vector.h +++ b/include/wx/vector.h @@ -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; diff --git a/tests/vectors/vectors.cpp b/tests/vectors/vectors.cpp index e3f6734c14..bf0fffa752 100644 --- a/tests/vectors/vectors.cpp +++ b/tests/vectors/vectors.cpp @@ -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 stdvec(rb, re); REQUIRE( stdvec.size() == 10 );