Merge branch 'iter-concepts'
Make wxList and wxVector iterators really iterators from C++ point of view, by defining all the expected types in them. See https://github.com/wxWidgets/wxWidgets/pull/744
This commit is contained in:
@@ -64,6 +64,14 @@ Changes in behaviour which may result in build errors
|
|||||||
wxGraphicsContext::CreatePen() continues to compile and work as before.
|
wxGraphicsContext::CreatePen() continues to compile and work as before.
|
||||||
|
|
||||||
|
|
||||||
|
3.1.2: (released 2018-??-??)
|
||||||
|
----------------------------
|
||||||
|
|
||||||
|
All:
|
||||||
|
|
||||||
|
- Make wxList and wxVector iterators conform to input iterator requirements.
|
||||||
|
|
||||||
|
|
||||||
3.1.1: (released 2018-02-19)
|
3.1.1: (released 2018-02-19)
|
||||||
----------------------------
|
----------------------------
|
||||||
|
|
||||||
|
@@ -599,6 +599,17 @@ private:
|
|||||||
// macros for definition of "template" list type
|
// macros for definition of "template" list type
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Helper macro defining common iterator typedefs
|
||||||
|
#if wxUSE_STD_CONTAINERS_COMPATIBLY
|
||||||
|
#include <iterator>
|
||||||
|
|
||||||
|
#define WX_DECLARE_LIST_ITER_DIFF_AND_CATEGORY() \
|
||||||
|
typedef std::ptrdiff_t difference_type; \
|
||||||
|
typedef std::bidirectional_iterator_tag iterator_category;
|
||||||
|
#else
|
||||||
|
#define WX_DECLARE_LIST_ITER_DIFF_AND_CATEGORY()
|
||||||
|
#endif
|
||||||
|
|
||||||
// and now some heavy magic...
|
// and now some heavy magic...
|
||||||
|
|
||||||
// declare a list type named 'name' and containing elements of type 'T *'
|
// declare a list type named 'name' and containing elements of type 'T *'
|
||||||
@@ -761,19 +772,21 @@ private:
|
|||||||
\
|
\
|
||||||
classexp iterator \
|
classexp iterator \
|
||||||
{ \
|
{ \
|
||||||
typedef name list; \
|
|
||||||
public: \
|
public: \
|
||||||
|
WX_DECLARE_LIST_ITER_DIFF_AND_CATEGORY() \
|
||||||
|
typedef T* value_type; \
|
||||||
|
typedef value_type* pointer; \
|
||||||
|
typedef value_type& reference; \
|
||||||
|
\
|
||||||
typedef nodetype Node; \
|
typedef nodetype Node; \
|
||||||
typedef iterator itor; \
|
typedef iterator itor; \
|
||||||
typedef T* value_type; \
|
|
||||||
typedef value_type* ptr_type; \
|
|
||||||
typedef value_type& reference; \
|
|
||||||
\
|
\
|
||||||
Node* m_node; \
|
Node* m_node; \
|
||||||
Node* m_init; \
|
Node* m_init; \
|
||||||
public: \
|
public: \
|
||||||
|
/* Compatibility typedefs, don't use */ \
|
||||||
typedef reference reference_type; \
|
typedef reference reference_type; \
|
||||||
typedef ptr_type pointer_type; \
|
typedef pointer pointer_type; \
|
||||||
\
|
\
|
||||||
iterator(Node* node, Node* init) : m_node(node), m_init(init) {}\
|
iterator(Node* node, Node* init) : m_node(node), m_init(init) {}\
|
||||||
iterator() : m_node(NULL), m_init(NULL) { } \
|
iterator() : m_node(NULL), m_init(NULL) { } \
|
||||||
@@ -811,19 +824,20 @@ private:
|
|||||||
}; \
|
}; \
|
||||||
classexp const_iterator \
|
classexp const_iterator \
|
||||||
{ \
|
{ \
|
||||||
typedef name list; \
|
|
||||||
public: \
|
public: \
|
||||||
typedef nodetype Node; \
|
WX_DECLARE_LIST_ITER_DIFF_AND_CATEGORY() \
|
||||||
typedef T* value_type; \
|
typedef T* value_type; \
|
||||||
typedef const value_type& const_reference; \
|
typedef const value_type* pointer; \
|
||||||
|
typedef const value_type& reference; \
|
||||||
|
\
|
||||||
|
typedef nodetype Node; \
|
||||||
typedef const_iterator itor; \
|
typedef const_iterator itor; \
|
||||||
typedef value_type* ptr_type; \
|
|
||||||
\
|
\
|
||||||
Node* m_node; \
|
Node* m_node; \
|
||||||
Node* m_init; \
|
Node* m_init; \
|
||||||
public: \
|
public: \
|
||||||
typedef const_reference reference_type; \
|
typedef reference reference_type; \
|
||||||
typedef const ptr_type pointer_type; \
|
typedef pointer pointer_type; \
|
||||||
\
|
\
|
||||||
const_iterator(Node* node, Node* init) \
|
const_iterator(Node* node, Node* init) \
|
||||||
: m_node(node), m_init(init) { } \
|
: m_node(node), m_init(init) { } \
|
||||||
@@ -864,19 +878,20 @@ private:
|
|||||||
}; \
|
}; \
|
||||||
classexp reverse_iterator \
|
classexp reverse_iterator \
|
||||||
{ \
|
{ \
|
||||||
typedef name list; \
|
|
||||||
public: \
|
public: \
|
||||||
typedef nodetype Node; \
|
WX_DECLARE_LIST_ITER_DIFF_AND_CATEGORY() \
|
||||||
typedef T* value_type; \
|
typedef T* value_type; \
|
||||||
typedef reverse_iterator itor; \
|
typedef value_type* pointer; \
|
||||||
typedef value_type* ptr_type; \
|
|
||||||
typedef value_type& reference; \
|
typedef value_type& reference; \
|
||||||
\
|
\
|
||||||
|
typedef nodetype Node; \
|
||||||
|
typedef reverse_iterator itor; \
|
||||||
|
\
|
||||||
Node* m_node; \
|
Node* m_node; \
|
||||||
Node* m_init; \
|
Node* m_init; \
|
||||||
public: \
|
public: \
|
||||||
typedef reference reference_type; \
|
typedef reference reference_type; \
|
||||||
typedef ptr_type pointer_type; \
|
typedef pointer pointer_type; \
|
||||||
\
|
\
|
||||||
reverse_iterator(Node* node, Node* init) \
|
reverse_iterator(Node* node, Node* init) \
|
||||||
: m_node(node), m_init(init) { } \
|
: m_node(node), m_init(init) { } \
|
||||||
@@ -903,19 +918,20 @@ private:
|
|||||||
}; \
|
}; \
|
||||||
classexp const_reverse_iterator \
|
classexp const_reverse_iterator \
|
||||||
{ \
|
{ \
|
||||||
typedef name list; \
|
|
||||||
public: \
|
public: \
|
||||||
typedef nodetype Node; \
|
WX_DECLARE_LIST_ITER_DIFF_AND_CATEGORY() \
|
||||||
typedef T* value_type; \
|
typedef T* value_type; \
|
||||||
|
typedef const value_type* pointer; \
|
||||||
|
typedef const value_type& reference; \
|
||||||
|
\
|
||||||
|
typedef nodetype Node; \
|
||||||
typedef const_reverse_iterator itor; \
|
typedef const_reverse_iterator itor; \
|
||||||
typedef value_type* ptr_type; \
|
|
||||||
typedef const value_type& const_reference; \
|
|
||||||
\
|
\
|
||||||
Node* m_node; \
|
Node* m_node; \
|
||||||
Node* m_init; \
|
Node* m_init; \
|
||||||
public: \
|
public: \
|
||||||
typedef const_reference reference_type; \
|
typedef reference reference_type; \
|
||||||
typedef const ptr_type pointer_type; \
|
typedef pointer pointer_type; \
|
||||||
\
|
\
|
||||||
const_reverse_iterator(Node* node, Node* init) \
|
const_reverse_iterator(Node* node, Node* init) \
|
||||||
: m_node(node), m_init(init) { } \
|
: m_node(node), m_init(init) { } \
|
||||||
|
@@ -33,6 +33,9 @@ inline void wxVectorSort(wxVector<T>& v)
|
|||||||
#include "wx/meta/if.h"
|
#include "wx/meta/if.h"
|
||||||
|
|
||||||
#include "wx/beforestd.h"
|
#include "wx/beforestd.h"
|
||||||
|
#if wxUSE_STD_CONTAINERS_COMPATIBLY
|
||||||
|
#include <iterator>
|
||||||
|
#endif
|
||||||
#include <new> // for placement new
|
#include <new> // for placement new
|
||||||
#include "wx/afterstd.h"
|
#include "wx/afterstd.h"
|
||||||
|
|
||||||
@@ -160,7 +163,7 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
typedef size_t size_type;
|
typedef size_t size_type;
|
||||||
typedef size_t difference_type;
|
typedef ptrdiff_t difference_type;
|
||||||
typedef T value_type;
|
typedef T value_type;
|
||||||
typedef value_type* pointer;
|
typedef value_type* pointer;
|
||||||
typedef const value_type* const_pointer;
|
typedef const value_type* const_pointer;
|
||||||
@@ -172,6 +175,14 @@ public:
|
|||||||
class reverse_iterator
|
class reverse_iterator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
#if wxUSE_STD_CONTAINERS_COMPATIBLY
|
||||||
|
typedef std::random_access_iterator_tag iterator_category;
|
||||||
|
#endif
|
||||||
|
typedef ptrdiff_t difference_type;
|
||||||
|
typedef T value_type;
|
||||||
|
typedef value_type* pointer;
|
||||||
|
typedef value_type& reference;
|
||||||
|
|
||||||
reverse_iterator() : m_ptr(NULL) { }
|
reverse_iterator() : m_ptr(NULL) { }
|
||||||
explicit reverse_iterator(iterator it) : m_ptr(it) { }
|
explicit reverse_iterator(iterator it) : m_ptr(it) { }
|
||||||
reverse_iterator(const reverse_iterator& it) : m_ptr(it.m_ptr) { }
|
reverse_iterator(const reverse_iterator& it) : m_ptr(it.m_ptr) { }
|
||||||
@@ -218,6 +229,14 @@ public:
|
|||||||
class const_reverse_iterator
|
class const_reverse_iterator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
#if wxUSE_STD_CONTAINERS_COMPATIBLY
|
||||||
|
typedef std::random_access_iterator_tag iterator_category;
|
||||||
|
#endif
|
||||||
|
typedef ptrdiff_t difference_type;
|
||||||
|
typedef T value_type;
|
||||||
|
typedef const value_type* pointer;
|
||||||
|
typedef const value_type& reference;
|
||||||
|
|
||||||
const_reverse_iterator() : m_ptr(NULL) { }
|
const_reverse_iterator() : m_ptr(NULL) { }
|
||||||
explicit const_reverse_iterator(const_iterator it) : m_ptr(it) { }
|
explicit const_reverse_iterator(const_iterator it) : m_ptr(it) { }
|
||||||
const_reverse_iterator(const reverse_iterator& it) : m_ptr(it.m_ptr) { }
|
const_reverse_iterator(const reverse_iterator& it) : m_ptr(it.m_ptr) { }
|
||||||
|
@@ -210,3 +210,27 @@ void ListsTestCase::wxListCtorTest()
|
|||||||
CPPUNIT_ASSERT( Baz::GetNumber() == 0 );
|
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
|
||||||
|
@@ -22,6 +22,10 @@
|
|||||||
|
|
||||||
#include "wx/vector.h"
|
#include "wx/vector.h"
|
||||||
|
|
||||||
|
#if wxUSE_STD_CONTAINERS_COMPATIBLY
|
||||||
|
#include <vector>
|
||||||
|
#endif // wxUSE_STD_CONTAINERS_COMPATIBLY
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// simple class capable of detecting leaks of its objects
|
// simple class capable of detecting leaks of its objects
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -360,6 +364,13 @@ TEST_CASE("wxVector::reverse_iterator", "[vector][reverse_iterator]")
|
|||||||
ri = rb + 2;
|
ri = rb + 2;
|
||||||
CHECK( ri - rb == 2 );
|
CHECK( ri - rb == 2 );
|
||||||
CHECK( re - ri == 8 );
|
CHECK( re - ri == 8 );
|
||||||
|
|
||||||
|
#if wxUSE_STD_CONTAINERS_COMPATIBLY
|
||||||
|
std::vector<int> stdvec(rb, re);
|
||||||
|
REQUIRE( stdvec.size() == 10 );
|
||||||
|
CHECK( stdvec[0] == 10 );
|
||||||
|
CHECK( stdvec[9] == 1 );
|
||||||
|
#endif // wxUSE_STD_CONTAINERS_COMPATIBLY
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("wxVector::capacity", "[vector][capacity][shrink_to_fit]")
|
TEST_CASE("wxVector::capacity", "[vector][capacity][shrink_to_fit]")
|
||||||
|
Reference in New Issue
Block a user