Make wxList iterators conform to input iterator requirements
Define "pointer", "reference", "difference_type" and "iterator_category" typedefs to ensure that wxList iterator classes are seen as iterators by the standard library in C++11 and later, as otherwise standard container template ctors taking iterators couldn't be used with them because they're only available if input iterator requirements are satisfied. This notably fixes creation of std::list from wxList iterators; add a test which didn't compile before to show it.
This commit is contained in:
@@ -210,3 +210,27 @@ void ListsTestCase::wxListCtorTest()
|
||||
CPPUNIT_ASSERT( Baz::GetNumber() == 0 );
|
||||
}
|
||||
|
||||
#if wxUSE_STD_CONTAINERS_COMPATIBLY
|
||||
|
||||
#include <list>
|
||||
|
||||
// Check that we convert wxList to std::list using the latter's ctor taking 2
|
||||
// iterators: this used to be broken in C++11 because wxList iterators didn't
|
||||
// fully implement input iterator requirements.
|
||||
TEST_CASE("wxList::iterator", "[list][std][iterator]")
|
||||
{
|
||||
Baz baz1("one"),
|
||||
baz2("two");
|
||||
|
||||
wxListBazs li;
|
||||
li.push_back(&baz1);
|
||||
li.push_back(&baz2);
|
||||
|
||||
std::list<Baz*> stdli(li.begin(), li.end());
|
||||
CHECK( stdli.size() == 2 );
|
||||
|
||||
const wxListBazs cli;
|
||||
CHECK( std::list<Baz*>(cli.begin(), cli.end()).empty() );
|
||||
}
|
||||
|
||||
#endif // wxUSE_STD_CONTAINERS_COMPATIBLY
|
||||
|
Reference in New Issue
Block a user