Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r82063 - in sandbox/static_vector: boost/container test
From: adam.wulkiewicz_at_[hidden]
Date: 2012-12-17 22:38:16


Author: awulkiew
Date: 2012-12-17 22:38:15 EST (Mon, 17 Dec 2012)
New Revision: 82063
URL: http://svn.boost.org/trac/boost/changeset/82063

Log:
returning of iterators added in insert() and erase()
Text files modified:
   sandbox/static_vector/boost/container/static_vector.hpp | 20 +++++++++++++++-----
   sandbox/static_vector/test/static_vector.cpp | 24 +++++++++++++++++-------
   2 files changed, 32 insertions(+), 12 deletions(-)

Modified: sandbox/static_vector/boost/container/static_vector.hpp
==============================================================================
--- sandbox/static_vector/boost/container/static_vector.hpp (original)
+++ sandbox/static_vector/boost/container/static_vector.hpp 2012-12-17 22:38:15 EST (Mon, 17 Dec 2012)
@@ -320,7 +320,7 @@
     }
 
     // basic
- void insert(iterator position, value_type const& value)
+ iterator insert(iterator position, value_type const& value)
     {
         errh::check_iterator_end_eq(*this, position);
         errh::check_capacity(*this, m_size + 1); // may throw
@@ -339,10 +339,12 @@
             this->move_backward(position, this->end() - 2, this->end() - 1); // may throw
             this->fill(position, value); // may throw
         }
+
+ return position;
     }
 
     // basic
- void insert(iterator position, size_type count, value_type const& value)
+ iterator insert(iterator position, size_type count, value_type const& value)
     {
         errh::check_iterator_end_eq(*this, position);
         errh::check_capacity(*this, m_size + count); // may throw
@@ -374,30 +376,36 @@
                 std::fill_n(position, to_move, value); // may throw
             }
         }
+
+ return position;
     }
 
     // basic
     template <typename Iterator>
- void insert(iterator position, Iterator first, Iterator last)
+ iterator insert(iterator position, Iterator first, Iterator last)
     {
         // TODO - add MPL_ASSERT, check if Iterator is really an iterator
 
         typedef typename boost::iterator_traversal<Iterator>::type traversal;
         this->insert_dispatch(position, first, last, traversal());
+
+ return position;
     }
 
     // basic
- void erase(iterator position)
+ iterator erase(iterator position)
     {
         errh::check_iterator_end_neq(*this, position);
 
         this->move(position + 1, this->end(), position); // may throw
         this->destroy(this->end() - 1);
         --m_size;
+
+ return position;
     }
 
     // basic
- void erase(iterator first, iterator last)
+ iterator erase(iterator first, iterator last)
     {
         errh::check_iterator_end_eq(*this, first);
         errh::check_iterator_end_eq(*this, last);
@@ -408,6 +416,8 @@
         this->move(last, this->end(), first); // may throw
         this->destroy(this->end() - n, this->end());
         m_size -= n;
+
+ return first;
     }
 
     // basic

Modified: sandbox/static_vector/test/static_vector.cpp
==============================================================================
--- sandbox/static_vector/test/static_vector.cpp (original)
+++ sandbox/static_vector/test/static_vector.cpp 2012-12-17 22:38:15 EST (Mon, 17 Dec 2012)
@@ -307,6 +307,7 @@
 void test_erase_nd()
 {
     static_vector<T, N> s;
+ typedef typename static_vector<T, N>::iterator It;
     
     for ( size_t i = 0 ; i < N ; ++i )
         s.push_back(T(i));
@@ -316,7 +317,8 @@
         for ( size_t i = 0 ; i < N ; ++i )
         {
             static_vector<T, N> s1(s);
- s1.erase(s1.begin() + i);
+ It it = s1.erase(s1.begin() + i);
+ BOOST_CHECK(s1.begin() + i == it);
             BOOST_CHECK(s1.size() == N - 1);
             for ( size_t j = 0 ; j < i ; ++j )
                 BOOST_CHECK(s1[j] == T(j));
@@ -331,7 +333,8 @@
         {
             static_vector<T, N> s1(s);
             size_t removed = i + n < N ? n : N - i;
- s1.erase(s1.begin() + i, s1.begin() + i + removed);
+ It it = s1.erase(s1.begin() + i, s1.begin() + i + removed);
+ BOOST_CHECK(s1.begin() + i == it);
             BOOST_CHECK(s1.size() == N - removed);
             for ( size_t j = 0 ; j < i ; ++j )
                 BOOST_CHECK(s1[j] == T(j));
@@ -350,6 +353,8 @@
     std::vector<T> v;
     std::list<T> l;
 
+ typedef typename static_vector<T, N>::iterator It;
+
     for ( size_t i = 0 ; i < h ; ++i )
     {
         s.push_back(T(i));
@@ -363,7 +368,8 @@
         for ( size_t i = 0 ; i <= h ; ++i )
         {
             static_vector<T, N> s1(s);
- s1.insert(s1.begin() + i, val);
+ It it = s1.insert(s1.begin() + i, val);
+ BOOST_CHECK(s1.begin() + i == it);
             BOOST_CHECK(s1.size() == h+1);
             for ( size_t j = 0 ; j < i ; ++j )
                 BOOST_CHECK(s1[j] == T(j));
@@ -378,7 +384,8 @@
         for ( size_t i = 0 ; i <= h ; ++i )
         {
             static_vector<T, N> s1(s);
- s1.insert(s1.begin() + i, n, val);
+ It it = s1.insert(s1.begin() + i, n, val);
+ BOOST_CHECK(s1.begin() + i == it);
             BOOST_CHECK(s1.size() == h+n);
             for ( size_t j = 0 ; j < i ; ++j )
                 BOOST_CHECK(s1[j] == T(j));
@@ -394,7 +401,8 @@
         for ( size_t i = 0 ; i <= h ; ++i )
         {
             static_vector<T, N> s1(s);
- s1.insert(s1.begin() + i, ss.begin(), ss.begin() + n);
+ It it = s1.insert(s1.begin() + i, ss.begin(), ss.begin() + n);
+ BOOST_CHECK(s1.begin() + i == it);
             BOOST_CHECK(s1.size() == h+n);
             for ( size_t j = 0 ; j < i ; ++j )
                 BOOST_CHECK(s1[j] == T(j));
@@ -409,7 +417,8 @@
         for ( size_t i = 0 ; i <= h ; ++i )
         {
             static_vector<T, N> s1(s);
- s1.insert(s1.begin() + i, v.begin(), v.begin() + n);
+ It it = s1.insert(s1.begin() + i, v.begin(), v.begin() + n);
+ BOOST_CHECK(s1.begin() + i == it);
             BOOST_CHECK(s1.size() == h+n);
             for ( size_t j = 0 ; j < i ; ++j )
                 BOOST_CHECK(s1[j] == T(j));
@@ -426,7 +435,8 @@
             static_vector<T, N> s1(s);
             typename std::list<T>::iterator it = l.begin();
             std::advance(it, n);
- s1.insert(s1.begin() + i, l.begin(), it);
+ It it1 = s1.insert(s1.begin() + i, l.begin(), it);
+ BOOST_CHECK(s1.begin() + i == it1);
             BOOST_CHECK(s1.size() == h+n);
             for ( size_t j = 0 ; j < i ; ++j )
                 BOOST_CHECK(s1[j] == T(j));


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk