Skip to content

Commit

Permalink
Make wxVector reverse iterators conform to iterator requirements
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
vadz committed Feb 23, 2018
1 parent 382a5a1 commit cc8fccf
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/changes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Changes in behaviour which may result in build errors

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)
Expand Down
19 changes: 19 additions & 0 deletions include/wx/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ inline void wxVectorSort(wxVector<T>& v)
#include "wx/meta/if.h"

#include "wx/beforestd.h"
#if wxUSE_STD_CONTAINERS_COMPATIBLY
#include <iterator>
#endif
#include <new> // for placement new
#include "wx/afterstd.h"

Expand Down Expand Up @@ -172,6 +175,14 @@ class wxVector
class reverse_iterator
{
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) { }
explicit reverse_iterator(iterator it) : m_ptr(it) { }
reverse_iterator(const reverse_iterator& it) : m_ptr(it.m_ptr) { }
Expand Down Expand Up @@ -218,6 +229,14 @@ class wxVector
class const_reverse_iterator
{
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) { }
explicit const_reverse_iterator(const_iterator it) : m_ptr(it) { }
const_reverse_iterator(const reverse_iterator& it) : m_ptr(it.m_ptr) { }
Expand Down
11 changes: 11 additions & 0 deletions tests/vectors/vectors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@

#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
// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -360,6 +364,13 @@ TEST_CASE("wxVector::reverse_iterator", "[vector][reverse_iterator]")
ri = rb + 2;
CHECK( ri - rb == 2 );
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]")
Expand Down

0 comments on commit cc8fccf

Please sign in to comment.