diff --git a/include/wx/list.h b/include/wx/list.h index ed9daff6ba..c261e96786 100644 --- a/include/wx/list.h +++ b/include/wx/list.h @@ -36,6 +36,7 @@ #if wxUSE_STD_CONTAINERS #include "wx/beforestd.h" #include + #include #include #include #include "wx/afterstd.h" @@ -121,6 +122,11 @@ public: bool operator !() const { return !( operator bool() ); } + bool operator==(std::nullptr_t) const + { return !*this; } + bool operator!=(std::nullptr_t) const + { return !(*this == nullptr); } + elT GetData() const { return *m_iter; } void SetData( elT e ) diff --git a/tests/lists/lists.cpp b/tests/lists/lists.cpp index b515b5a285..4f07431396 100644 --- a/tests/lists/lists.cpp +++ b/tests/lists/lists.cpp @@ -194,6 +194,29 @@ TEST_CASE("wxList::ctor", "[list]") CHECK( Baz::GetNumber() == 0 ); } +TEST_CASE("wxList::iterator::cmp", "[list]") +{ + int dummy[2]; + + wxListInt list; + list.push_back(dummy); + list.push_back(dummy + 1); + + wxListInt::compatibility_iterator it = list.GetFirst(); + CHECK( it == it ); + CHECK( it != nullptr ); + + const wxListInt::compatibility_iterator last = list.GetLast(); + CHECK( last != nullptr ); + CHECK( it != last ); + + it = list.Item(1); + CHECK( it == last ); + + it = list.Find(dummy + 2); + CHECK( it == nullptr ); +} + // Check for WX_DECLARE_LIST_3 which is used to define wxWindowList: we can't // use this class itself here, as it's in the GUI library, so declare something // similar.