Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r84672 - in sandbox/varray: boost/container/detail test
From: adam.wulkiewicz_at_[hidden]
Date: 2013-06-07 10:19:55


Author: awulkiew
Date: 2013-06-07 10:19:55 EDT (Fri, 07 Jun 2013)
New Revision: 84672
URL: http://svn.boost.org/trac/boost/changeset/84672

Log:
sandbox/varray: the container is no longer cleared after move(). Rval refs handled in insert().

Text files modified:
   sandbox/varray/boost/container/detail/varray.hpp | 89 ++++++++++++++++++++-------------------
   sandbox/varray/boost/container/detail/varray_util.hpp | 4
   sandbox/varray/test/varray_test.cpp | 8 +-
   3 files changed, 51 insertions(+), 50 deletions(-)

Modified: sandbox/varray/boost/container/detail/varray.hpp
==============================================================================
--- sandbox/varray/boost/container/detail/varray.hpp Fri Jun 7 04:20:48 2013 (r84671)
+++ sandbox/varray/boost/container/detail/varray.hpp 2013-06-07 10:19:55 EDT (Fri, 07 Jun 2013) (r84672)
@@ -734,7 +734,7 @@
         errh::check_capacity(*this, m_size + 1); // may throw
 
         namespace sv = varray_detail;
- sv::construct(dti(), this->end(), value); // may throw
+ sv::construct(dti(), this->end(), ::boost::move(value)); // may throw
         ++m_size; // update end
     }
 
@@ -776,7 +776,28 @@
     //! Constant or linear.
     iterator insert(iterator position, value_type const& value)
     {
- return this->priv_insert(position, value);
+ typedef typename vt::disable_trivial_init dti;
+ namespace sv = varray_detail;
+
+ errh::check_iterator_end_eq(*this, position);
+ errh::check_capacity(*this, m_size + 1); // may throw
+
+ if ( position == this->end() )
+ {
+ sv::construct(dti(), position, value); // may throw
+ ++m_size; // update end
+ }
+ else
+ {
+ // TODO - should move be used only if it's nonthrowing?
+ value_type & r = *(this->end() - 1);
+ sv::construct(dti(), this->end(), boost::move(r)); // may throw
+ ++m_size; // update end
+ sv::move_backward(position, this->end() - 2, this->end() - 1); // may throw
+ sv::assign(position, value); // may throw
+ }
+
+ return position;
     }
 
     //! @pre
@@ -798,7 +819,28 @@
     //! Constant or linear.
     iterator insert(iterator position, BOOST_RV_REF(value_type) value)
     {
- return this->priv_insert(position, value);
+ typedef typename vt::disable_trivial_init dti;
+ namespace sv = varray_detail;
+
+ errh::check_iterator_end_eq(*this, position);
+ errh::check_capacity(*this, m_size + 1); // may throw
+
+ if ( position == this->end() )
+ {
+ sv::construct(dti(), position, boost::move(value)); // may throw
+ ++m_size; // update end
+ }
+ else
+ {
+ // TODO - should move be used only if it's nonthrowing?
+ value_type & r = *(this->end() - 1);
+ sv::construct(dti(), this->end(), boost::move(r)); // may throw
+ ++m_size; // update end
+ sv::move_backward(position, this->end() - 2, this->end() - 1); // may throw
+ sv::assign(position, boost::move(value)); // may throw
+ }
+
+ return position;
     }
 
     //! @pre
@@ -1532,7 +1574,6 @@
     {
         ::memcpy(this->data(), other.data(), sizeof(Value) * other.m_size);
         m_size = other.m_size;
- other.m_size = 0;
     }
 
     // @par Throws
@@ -1546,8 +1587,6 @@
         namespace sv = varray_detail;
         sv::uninitialized_move_if_noexcept(other.begin(), other.end(), this->begin()); // may throw
         m_size = other.m_size;
- sv::destroy(other.begin(), other.end());
- other.m_size = 0;
     }
 
     // @par Throws
@@ -1584,8 +1623,6 @@
             sv::destroy(this->begin() + other.size(), this->end());
         }
         m_size = other.size(); // update end
-
- other.clear();
     }
 
     // @par Throws
@@ -1681,42 +1718,6 @@
     // insert
 
     // @par Throws
- // If Value's move constructor or move assignment throws
- // or if Value's copy assignment throws.
- // @par Complexity
- // Linear O(N).
- template <typename V>
- iterator priv_insert(iterator position, V & value)
- {
- typedef typename vt::disable_trivial_init dti;
- namespace sv = varray_detail;
-
- errh::check_iterator_end_eq(*this, position);
- errh::check_capacity(*this, m_size + 1); // may throw
-
- if ( position == this->end() )
- {
- sv::construct(dti(), position, value); // may throw
- ++m_size; // update end
- }
- else
- {
- // TODO - should following lines check for exception and revert to the old size?
-
- // TODO - should move be used only if it's nonthrowing?
- value_type & r = *(this->end() - 1);
- sv::construct(dti(), this->end(), boost::move(r)); // may throw
- ++m_size; // update end
- sv::move_backward(position, this->end() - 2, this->end() - 1); // may throw
- sv::assign(position, value); // may throw
- }
-
- return position;
- }
-
- // insert
-
- // @par Throws
     // If Value's move constructor, move assignment throws
     // or if Value's copy constructor or copy assignment throws.
     // @par Complexity

Modified: sandbox/varray/boost/container/detail/varray_util.hpp
==============================================================================
--- sandbox/varray/boost/container/detail/varray_util.hpp Fri Jun 7 04:20:48 2013 (r84671)
+++ sandbox/varray/boost/container/detail/varray_util.hpp 2013-06-07 10:19:55 EDT (Fri, 07 Jun 2013) (r84672)
@@ -574,7 +574,7 @@
     use_memcpy;
 
     typedef typename boost::iterator_value<I>::type V;
- new (static_cast<void*>(boost::addressof(*pos))) V(p); // may throw
+ new (static_cast<void*>(boost::addressof(*pos))) V(::boost::move(p)); // may throw
 }
 
 // Needed by emplace_back() and emplace()
@@ -654,7 +654,7 @@
 inline
 void assign(I pos, BOOST_RV_REF(V) v)
 {
- *pos = v; // may throw
+ *pos = boost::move(v); // may throw
 }
 
 

Modified: sandbox/varray/test/varray_test.cpp
==============================================================================
--- sandbox/varray/test/varray_test.cpp Fri Jun 7 04:20:48 2013 (r84671)
+++ sandbox/varray/test/varray_test.cpp 2013-06-07 10:19:55 EDT (Fri, 07 Jun 2013) (r84672)
@@ -512,9 +512,9 @@
 
         BOOST_CHECK(v1.size() == N/2);
         BOOST_CHECK(s1.size() == N);
- BOOST_CHECK(v2.size() == 0);
+ BOOST_CHECK(v2.size() == N); // objects aren't destroyed
         BOOST_CHECK(s2.size() == N);
- BOOST_CHECK(v3.size() == 0);
+ BOOST_CHECK(v3.size() == N); // objects aren't destroyed
         BOOST_CHECK(s3.size() == N);
         BOOST_CHECK(v4.size() == N/2);
         BOOST_CHECK(s4.size() == N);
@@ -553,9 +553,9 @@
 
         BOOST_CHECK(v1.size() == N/3);
         BOOST_CHECK(s1.size() == N/2);
- BOOST_CHECK(v2.size() == 0);
+ BOOST_CHECK(v2.size() == N/2); // objects aren't destroyed
         BOOST_CHECK(s2.size() == N/2);
- BOOST_CHECK(v3.size() == 0);
+ BOOST_CHECK(v3.size() == N/2); // objects aren't destroyed
         BOOST_CHECK(s3.size() == N/2);
         for (size_t i = 0 ; i < N/3 ; ++i )
             BOOST_CHECK(v1[i] == T(100 + i));


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