From c51fbe50b912a66df77e29d976f6d3675f8d9aef Mon Sep 17 00:00:00 2001 From: Adam Wulkiewicz Date: Sun, 16 Dec 2012 19:34:51 +0000 Subject: [PATCH] Iterators check changed in erase(f, l). Tests upgraded. [SVN r82032] --- .../extensions/index/static_vector.hpp | 20 +++++--- test/static_vector.cpp | 50 ++++++++----------- 2 files changed, 34 insertions(+), 36 deletions(-) diff --git a/include/boost/geometry/extensions/index/static_vector.hpp b/include/boost/geometry/extensions/index/static_vector.hpp index 2721fd684..1d7d74456 100644 --- a/include/boost/geometry/extensions/index/static_vector.hpp +++ b/include/boost/geometry/extensions/index/static_vector.hpp @@ -257,8 +257,8 @@ public: // basic void erase(iterator first, iterator last) { - check_iterator_end_neq(first); - check_iterator_end_neq(last); + check_iterator_end_eq(first); + check_iterator_end_eq(last); difference_type n = std::distance(first, last); BOOST_ASSERT_MSG(0 <= n, "invalid range"); @@ -754,9 +754,11 @@ private: BOOST_ASSERT_MSG(0 < m_size, "the container is empty"); } - void check_iterator_end_neq(iterator position) + void check_iterator_end_neq(const_iterator position) { - BOOST_GEOMETRY_INDEX_ASSERT_UNUSED_PARAM( + BOOST_ASSERT_MSG(this->begin() <= position && position < this->end(), "iterator out of bounds"); + + /*BOOST_GEOMETRY_INDEX_ASSERT_UNUSED_PARAM( difference_type dist = std::distance(this->begin(), position); ) BOOST_ASSERT_MSG( @@ -765,12 +767,14 @@ private: (static_cast(dist) < m_size) : ( dist < static_cast(m_size)) ), "invalid iterator" - ); + );*/ } - void check_iterator_end_eq(iterator position) + void check_iterator_end_eq(const_iterator position) { - BOOST_GEOMETRY_INDEX_ASSERT_UNUSED_PARAM( + BOOST_ASSERT_MSG(this->begin() <= position && position <= this->end(), "iterator out of bounds"); + + /*BOOST_GEOMETRY_INDEX_ASSERT_UNUSED_PARAM( difference_type dist = std::distance(this->begin(), position); ) BOOST_ASSERT_MSG( @@ -779,7 +783,7 @@ private: (static_cast(dist) <= m_size) : ( dist <= static_cast(m_size)) ), "invalid iterator" - ); + );*/ } Value * ptr() diff --git a/test/static_vector.cpp b/test/static_vector.cpp index b45ed1a03..9dca95562 100644 --- a/test/static_vector.cpp +++ b/test/static_vector.cpp @@ -307,39 +307,33 @@ void test_erase_nd() for ( size_t i = 0 ; i < N ; ++i ) s.push_back(T(i)); + // erase(pos) { - static_vector s1(s); - - for ( size_t i = 1 ; i < N ; ++i ) + for ( size_t i = 0 ; i < N ; ++i ) { - BOOST_CHECK(s1.front() == T(i-1)); - s1.erase(s1.begin()); - BOOST_CHECK(s1.front() == T(i)); - } - BOOST_CHECK(s1.size() == 1); + static_vector s1(s); + s1.erase(s1.begin() + i); + BOOST_CHECK(s1.size() == N - 1); + for ( size_t j = 0 ; j < i ; ++j ) + BOOST_CHECK(s1[j] == T(j)); + for ( size_t j = i+1 ; j < N ; ++j ) + BOOST_CHECK(s1[j-1] == T(j)); + } } - + // erase(first, last) { - static_vector s1(s); - - for ( size_t i = N ; i > 1 ; --i ) + size_t n = N/3; + for ( size_t i = 0 ; i <= N ; ++i ) { - BOOST_CHECK(s1.back() == T(i-1)); - s1.erase(s1.end() - 1); - BOOST_CHECK(s1.back() == T(i-2)); - } - BOOST_CHECK(s1.size() == 1); - } - - { - static_vector s1(s); - - for ( size_t i = 1 ; i < N - 2 ; i += 3 ) - { - BOOST_CHECK(s1.front() == T(i-1)); - s1.erase(s1.begin(), s1.begin() + 3); - BOOST_CHECK(s1.front() == T(i+2)); - } + static_vector s1(s); + size_t removed = i + n < N ? n : N - i; + s1.erase(s1.begin() + i, s1.begin() + i + removed); + BOOST_CHECK(s1.size() == N - removed); + for ( size_t j = 0 ; j < i ; ++j ) + BOOST_CHECK(s1[j] == T(j)); + for ( size_t j = i+n ; j < N ; ++j ) + BOOST_CHECK(s1[j-n] == T(j)); + } } }