Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r56249 - trunk/boost/numeric/ublas
From: guwi17_at_[hidden]
Date: 2009-09-16 18:05:01


Author: guwi17
Date: 2009-09-16 18:05:00 EDT (Wed, 16 Sep 2009)
New Revision: 56249
URL: http://svn.boost.org/trac/boost/changeset/56249

Log:
see #3457
 * matrix.hpp: added move semantics
 * vector.hpp: added move semantics

Text files modified:
   trunk/boost/numeric/ublas/matrix.hpp | 32 +++++++++++++++++++++++++++++++-
   trunk/boost/numeric/ublas/vector.hpp | 32 +++++++++++++++++++++++++++++++-
   2 files changed, 62 insertions(+), 2 deletions(-)

Modified: trunk/boost/numeric/ublas/matrix.hpp
==============================================================================
--- trunk/boost/numeric/ublas/matrix.hpp (original)
+++ trunk/boost/numeric/ublas/matrix.hpp 2009-09-16 18:05:00 EDT (Wed, 16 Sep 2009)
@@ -180,6 +180,15 @@
         }
 
         // Assignment
+#ifdef BOOST_UBLAS_MOVE_SEMANTICS
+
+ /*! @note "pass by value" the key idea to enable move semantics */
+ BOOST_UBLAS_INLINE
+ matrix &operator = (matrix m) {
+ assign_temporary(m);
+ return *this;
+ }
+#else
         BOOST_UBLAS_INLINE
         matrix &operator = (const matrix &m) {
             size1_ = m.size1_;
@@ -187,6 +196,7 @@
             data () = m.data ();
             return *this;
         }
+#endif
         template<class C> // Container assignment without temporary
         BOOST_UBLAS_INLINE
         matrix &operator = (const matrix_container<C> &m) {
@@ -1005,11 +1015,21 @@
         ~bounded_matrix () {}
 
         // Assignment
+#ifdef BOOST_UBLAS_MOVE_SEMANTICS
+
+ /*! @note "pass by value" the key idea to enable move semantics */
+ BOOST_UBLAS_INLINE
+ bounded_matrix &operator = (bounded_matrix m) {
+ matrix_type::operator = (m);
+ return *this;
+ }
+#else
         BOOST_UBLAS_INLINE
         bounded_matrix &operator = (const bounded_matrix &m) {
             matrix_type::operator = (m);
             return *this;
         }
+#endif
         template<class L2, class A2> // Generic matrix assignment
         BOOST_UBLAS_INLINE
         bounded_matrix &operator = (const matrix<T, L2, A2> &m) {
@@ -3298,7 +3318,7 @@
             size1_ (m.size1_), size2_ (m.size2_) /* , data_ () */ {
             if (size1_ > N || size2_ > M)
                 bad_size ().raise ();
- *this = m;
+ assign(m);
         }
         template<class AE>
         BOOST_UBLAS_INLINE
@@ -3382,6 +3402,15 @@
         }
 
         // Assignment
+#ifdef BOOST_UBLAS_MOVE_SEMANTICS
+
+ /*! @note "pass by value" the key idea to enable move semantics */
+ BOOST_UBLAS_INLINE
+ c_matrix &operator = (c_matrix m) {
+ assign_temporary(m);
+ return *this;
+ }
+#else
         BOOST_UBLAS_INLINE
         c_matrix &operator = (const c_matrix &m) {
             size1_ = m.size1_;
@@ -3390,6 +3419,7 @@
                 std::copy (m.data_ [i], m.data_ [i] + m.size2_, data_ [i]);
             return *this;
         }
+#endif
         template<class C> // Container assignment without temporary
         BOOST_UBLAS_INLINE
         c_matrix &operator = (const matrix_container<C> &m) {

Modified: trunk/boost/numeric/ublas/vector.hpp
==============================================================================
--- trunk/boost/numeric/ublas/vector.hpp (original)
+++ trunk/boost/numeric/ublas/vector.hpp 2009-09-16 18:05:00 EDT (Wed, 16 Sep 2009)
@@ -157,11 +157,21 @@
         }
 
         // Assignment
+#ifdef BOOST_UBLAS_MOVE_SEMANTICS
+
+ /*! @note "pass by value" the key idea to enable move semantics */
+ BOOST_UBLAS_INLINE
+ vector &operator = (vector v) {
+ assign_temporary(v);
+ return *this;
+ }
+#else
         BOOST_UBLAS_INLINE
         vector &operator = (const vector &v) {
             data () = v.data ();
             return *this;
         }
+#endif
         template<class C> // Container assignment without temporary
         BOOST_UBLAS_INLINE
         vector &operator = (const vector_container<C> &v) {
@@ -550,11 +560,21 @@
         ~bounded_vector () {}
 
         // Assignment
+#ifdef BOOST_UBLAS_MOVE_SEMANTICS
+
+ /*! @note "pass by value" the key idea to enable move semantics */
+ BOOST_UBLAS_INLINE
+ bounded_vector &operator = (bounded_vector v) {
+ vector_type::operator = (v);
+ return *this;
+ }
+#else
         BOOST_UBLAS_INLINE
         bounded_vector &operator = (const bounded_vector &v) {
             vector_type::operator = (v);
             return *this;
         }
+#endif
         template<class A2> // Generic vector assignment
         BOOST_UBLAS_INLINE
         bounded_vector &operator = (const vector<T, A2> &v) {
@@ -1276,7 +1296,7 @@
             size_ (v.size_) /* , data_ () */ {
             if (size_ > N)
                 bad_size ().raise ();
- *this = v;
+ assign(v);
         }
         template<class AE>
         BOOST_UBLAS_INLINE
@@ -1359,12 +1379,22 @@
         }
 
         // Assignment
+#ifdef BOOST_UBLAS_MOVE_SEMANTICS
+
+ /*! @note "pass by value" the key idea to enable move semantics */
+ BOOST_UBLAS_INLINE
+ c_vector &operator = (c_vector v) {
+ assign_temporary(v);
+ return *this;
+ }
+#else
         BOOST_UBLAS_INLINE
         c_vector &operator = (const c_vector &v) {
             size_ = v.size_;
             std::copy (v.data_, v.data_ + v.size_, data_);
             return *this;
         }
+#endif
         template<class C> // Container assignment without temporary
         BOOST_UBLAS_INLINE
         c_vector &operator = (const vector_container<C> &v) {


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