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:
Vadim Zeitlin
2018-02-23 15:47:12 +01:00
parent 0d5378fb84
commit fdbe357e4b
3 changed files with 64 additions and 6 deletions

View File

@@ -599,6 +599,17 @@ private:
// 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...
// declare a list type named 'name' and containing elements of type 'T *'
@@ -762,15 +773,19 @@ private:
classexp iterator \
{ \
public: \
WX_DECLARE_LIST_ITER_DIFF_AND_CATEGORY() \
typedef T* value_type; \
typedef value_type* pointer; \
typedef value_type& reference; \
\
typedef nodetype Node; \
typedef iterator itor; \
typedef T* value_type; \
typedef value_type* ptr_type; \
typedef value_type& reference; \
\
Node* m_node; \
Node* m_init; \
public: \
/* Compatibility typedefs, don't use */ \
typedef reference reference_type; \
typedef ptr_type pointer_type; \
\
@@ -811,8 +826,12 @@ private:
classexp const_iterator \
{ \
public: \
typedef nodetype Node; \
WX_DECLARE_LIST_ITER_DIFF_AND_CATEGORY() \
typedef T* value_type; \
typedef const value_type* pointer; \
typedef const value_type& reference; \
\
typedef nodetype Node; \
typedef const value_type& const_reference; \
typedef const_iterator itor; \
typedef value_type* ptr_type; \
@@ -863,11 +882,14 @@ private:
classexp reverse_iterator \
{ \
public: \
typedef nodetype Node; \
WX_DECLARE_LIST_ITER_DIFF_AND_CATEGORY() \
typedef T* value_type; \
typedef value_type* pointer; \
typedef value_type& reference; \
\
typedef nodetype Node; \
typedef reverse_iterator itor; \
typedef value_type* ptr_type; \
typedef value_type& reference; \
\
Node* m_node; \
Node* m_init; \
@@ -901,8 +923,12 @@ private:
classexp const_reverse_iterator \
{ \
public: \
typedef nodetype Node; \
WX_DECLARE_LIST_ITER_DIFF_AND_CATEGORY() \
typedef T* value_type; \
typedef const value_type* pointer; \
typedef const value_type& reference; \
\
typedef nodetype Node; \
typedef const_reverse_iterator itor; \
typedef value_type* ptr_type; \
typedef const value_type& const_reference; \