Make wxVector reverse iterators conform to iterator requirements

This is similar to a recent commit adding the missing typedefs to wxList
iterators and defines the types required by the iterator concept in
wxVector::reverse_iterator and const_reverse_iterator classes (simple
iterators are just pointers and are already covered by the standard
iterator_traits specialization).
This commit is contained in:
Vadim Zeitlin 2018-02-23 16:14:03 +01:00
parent 382a5a156e
commit cc8fccf0bc
3 changed files with 31 additions and 1 deletions

View File

@ -69,7 +69,7 @@ Changes in behaviour which may result in build errors
All: All:
- Make wxList iterators conform to input iterator requirements. - Make wxList and wxVector iterators conform to input iterator requirements.
3.1.1: (released 2018-02-19) 3.1.1: (released 2018-02-19)

View File

@ -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"
@ -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) { }

View File

@ -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]")