Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r82148 - sandbox/static_vector/boost/container
From: adam.wulkiewicz_at_[hidden]
Date: 2012-12-21 08:33:45


Author: awulkiew
Date: 2012-12-21 08:33:44 EST (Fri, 21 Dec 2012)
New Revision: 82148
URL: http://svn.boost.org/trac/boost/changeset/82148

Log:
Implemented nothrowing move ctor and move assignment for the same static_vector type
Text files modified:
   sandbox/static_vector/boost/container/static_vector.hpp | 24 ++++++++++++++----------
   1 files changed, 14 insertions(+), 10 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-21 08:33:44 EST (Fri, 21 Dec 2012)
@@ -191,7 +191,7 @@
     static_vector(static_vector<value_type, C, S> const& other)
         : m_size(other.size())
     {
- errh::check_capacity(other.size()); // may throw
+ errh::check_capacity(*this, other.size()); // may throw
         
         namespace sv = static_vector_detail;
         sv::uninitialized_copy(other.begin(), other.end(), this->begin()); // may throw
@@ -222,14 +222,17 @@
 
     // Move constructors
 
- // nothrow or basic (depends on traits)
+ // nothrow
+ // (note: linear complexity)
     static_vector(BOOST_RV_REF(static_vector) other)
- : m_size(0)
+ : m_size(other.m_size)
     {
- this->swap(other); // may throw
+ ::memcpy(this->data(), other.data(), sizeof(Value) * other.m_size);
+ other.m_size = 0;
     }
 
- // basic
+ // nothrow or basic (depends on traits)
+ // (note: linear complexity)
     template <std::size_t C, typename S>
 #if defined(BOOST_NO_RVALUE_REFERENCES)
     static_vector(boost::rv< static_vector<value_type, C, S> > & other)
@@ -238,18 +241,19 @@
 #endif
         : m_size(0)
     {
- this->swap(other); // may throw
+ this->swap(other);
     }
 
     // Move assignments
 
- // nothrow or basic (depends on traits)
+ // nothrow
     static_vector & operator=(BOOST_RV_REF(static_vector) other)
     {
         this->clear();
- this->swap(other);
- //this->swap(other);
- //other.clear();
+
+ ::memcpy(this->data(), other.data(), sizeof(Value) * other.m_size);
+ boost::swap(m_size, other.m_size);
+
         return *this;
     }
 


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