diff --git a/docs/changes.txt b/docs/changes.txt index 7f91d492bb..f4867d6ac6 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -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) diff --git a/include/wx/vector.h b/include/wx/vector.h index 49b0840c9f..8a7ae1b228 100644 --- a/include/wx/vector.h +++ b/include/wx/vector.h @@ -33,6 +33,9 @@ inline void wxVectorSort(wxVector& v) #include "wx/meta/if.h" #include "wx/beforestd.h" +#if wxUSE_STD_CONTAINERS_COMPATIBLY +#include +#endif #include // for placement new #include "wx/afterstd.h" @@ -172,6 +175,14 @@ public: 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) { } @@ -218,6 +229,14 @@ public: 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) { } diff --git a/tests/vectors/vectors.cpp b/tests/vectors/vectors.cpp index 25a9a5cdd5..e3f6734c14 100644 --- a/tests/vectors/vectors.cpp +++ b/tests/vectors/vectors.cpp @@ -22,6 +22,10 @@ #include "wx/vector.h" +#if wxUSE_STD_CONTAINERS_COMPATIBLY + #include +#endif // wxUSE_STD_CONTAINERS_COMPATIBLY + // ---------------------------------------------------------------------------- // simple class capable of detecting leaks of its objects // ---------------------------------------------------------------------------- @@ -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 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]")