diff --git a/include/wx/vector.h b/include/wx/vector.h index 686dc0a587..ed4bbd3a40 100644 --- a/include/wx/vector.h +++ b/include/wx/vector.h @@ -368,6 +368,25 @@ public: return *this; } + bool operator==(const wxVector& vb) const + { + if ( vb.m_size != m_size ) + return false; + + for ( size_type i = 0; i < m_size; i++ ) + { + if ( vb.m_values[i] != m_values[i] ) + return false; + } + + return true; + } + + bool operator!=(const wxVector& vb) const + { + return !(*this == vb); + } + void push_back(const value_type& v) { reserve(size() + 1); diff --git a/interface/wx/vector.h b/interface/wx/vector.h index f8b32e26d2..982f5e26d9 100644 --- a/interface/wx/vector.h +++ b/interface/wx/vector.h @@ -199,6 +199,20 @@ public: */ wxVector& operator=(const wxVector& vb); + /** + Equality operator. + + @since 3.1.1 + */ + wxVector& operator==(const wxVector& vb) const; + + /** + Inequality operator. + + @since 3.1.1 + */ + wxVector& operator!=(const wxVector& vb) const; + /** Returns item at position @a idx. */ diff --git a/tests/vectors/vectors.cpp b/tests/vectors/vectors.cpp index 001f79eabc..070babe160 100644 --- a/tests/vectors/vectors.cpp +++ b/tests/vectors/vectors.cpp @@ -314,3 +314,20 @@ void VectorsTestCase::Sort() CPPUNIT_ASSERT( v[idx-1] <= v[idx] ); } } + +TEST_CASE("wxVector::operator==", "[vector][compare]") +{ + wxVector v1, v2; + CHECK( v1 == v2 ); + CHECK( !(v1 != v2) ); + + v1.push_back("foo"); + CHECK( v1 != v2 ); + + v2.push_back("foo"); + CHECK( v1 == v2 ); + + v1.push_back("bar"); + v2.push_back("baz"); + CHECK( v1 != v2 ); +}