mirror of
https://github.com/wxWidgets/wxWidgets.git
synced 2026-03-23 18:54:01 +08:00
Allow comparing wxList::compatibility_iterator with nullptr
This doesn't cost anything but allows the old code which relied on compatibility_iterator being implicitly convertible to a pointer (and hence comparable with nullptr) continue to compile and work. Add a unit test checking that this works as expected.
This commit is contained in:
@@ -36,6 +36,7 @@
|
||||
#if wxUSE_STD_CONTAINERS
|
||||
#include "wx/beforestd.h"
|
||||
#include <algorithm>
|
||||
#include <cstddef>
|
||||
#include <iterator>
|
||||
#include <list>
|
||||
#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 )
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user