|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r83053 - sandbox/tuple-move/detail
From: adam.wulkiewicz_at_[hidden]
Date: 2013-02-20 18:07:04
Author: awulkiew
Date: 2013-02-20 18:07:03 EST (Wed, 20 Feb 2013)
New Revision: 83053
URL: http://svn.boost.org/trac/boost/changeset/83053
Log:
tuples::cons move semantics - compiling in VS2010, not compiling in mingw -std=c++98
Text files modified:
sandbox/tuple-move/detail/tuple_basic.hpp | 62 ++++++++++++++++++++++++++++++++++-----
1 files changed, 54 insertions(+), 8 deletions(-)
Modified: sandbox/tuple-move/detail/tuple_basic.hpp
==============================================================================
--- sandbox/tuple-move/detail/tuple_basic.hpp (original)
+++ sandbox/tuple-move/detail/tuple_basic.hpp 2013-02-20 18:07:03 EST (Wed, 20 Feb 2013)
@@ -38,6 +38,7 @@
#include "boost/type_traits/cv_traits.hpp"
#include "boost/type_traits/function_traits.hpp"
#include "boost/utility/swap.hpp"
+#include "boost/move/move.hpp"
#include "boost/detail/workaround.hpp" // needed for BOOST_WORKAROUND
@@ -64,7 +65,7 @@
} // end detail
// - cons forward declaration -----------------------------------------------
-template <class HT, class TT> struct cons;
+template <class HT, class TT> class cons;
// - tuple forward declaration -----------------------------------------------
@@ -254,7 +255,21 @@
} // detail
template <class HT, class TT>
-struct cons {
+class cons {
+
+ BOOST_COPYABLE_AND_MOVABLE(cons)
+
+#ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
+public:
+ template <class HT2, class TT2>
+ cons& operator=(cons<HT2, TT2> & t)
+ { this->operator=(static_cast<const ::boost::rv<cons<HT2, TT2> > &>(const_cast<const cons<HT2, TT2> &>(t))); return *this;}
+ template <class T1, class T2>
+ cons& operator=(std::pair<T1, T2> & t)
+ { this->operator=(static_cast<const ::boost::rv<std::pair<T1, T2> > &>(const_cast<const std::pair<T1, T2> &>(t))); return *this;}
+#endif
+
+public:
typedef HT head_type;
typedef TT tail_type;
@@ -308,23 +323,37 @@
template <class HT2, class TT2>
cons( const cons<HT2, TT2>& u ) : head(u.head), tail(u.tail) {}
+ template <class HT2, class TT2>
+ cons( BOOST_RV_REF_2_TEMPL_ARGS(cons, HT2, TT2) u ) : head(::boost::move(u.head)), tail(::boost::move(u.tail)) {}
template <class HT2, class TT2>
- cons& operator=( const cons<HT2, TT2>& u ) {
+ cons& operator=( BOOST_COPY_ASSIGN_REF_2_TEMPL_ARGS(cons, HT2, TT2) u ) {
head=u.head; tail=u.tail; return *this;
}
+ template <class HT2, class TT2>
+ cons& operator=( BOOST_RV_REF_2_TEMPL_ARGS(cons, HT2, TT2) u ) {
+ head=::boost::move(u.head); tail=::boost::move(u.tail); return *this;
+ }
// must define assignment operator explicitly, implicit version is
// illformed if HT is a reference (12.8. (12))
- cons& operator=(const cons& u) {
+ cons& operator=(BOOST_COPY_ASSIGN_REF(cons) u) {
head = u.head; tail = u.tail; return *this;
}
+ cons& operator=(BOOST_RV_REF(cons) u) {
+ head=::boost::move(u.head); tail=::boost::move(u.tail); return *this;
+ }
template <class T1, class T2>
- cons& operator=( const std::pair<T1, T2>& u ) {
+ cons& operator=( BOOST_COPY_ASSIGN_REF_2_TEMPL_ARGS(std::pair, T1, T2) u ) {
BOOST_STATIC_ASSERT(length<cons>::value == 2); // check length = 2
head = u.first; tail.head = u.second; return *this;
}
+ template <class T1, class T2>
+ cons& operator=( BOOST_RV_REF_2_TEMPL_ARGS(std::pair, T1, T2) u ) {
+ BOOST_STATIC_ASSERT(length<cons>::value == 2); // check length = 2
+ head = ::boost::move(u.first); tail.head = ::boost::move(u.second); return *this;
+ }
// get member functions (non-const and const)
template <int N>
@@ -345,7 +374,18 @@
};
template <class HT>
-struct cons<HT, null_type> {
+class cons<HT, null_type> {
+
+ BOOST_COPYABLE_AND_MOVABLE(cons)
+
+#ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
+public:
+ template <class HT2>
+ cons& operator=(cons<HT2, null_type> & t)
+ { this->operator=(static_cast<const ::boost::rv<cons<HT2, null_type> > &>(const_cast<const cons<HT2, null_type> &>(t))); return *this;}
+#endif
+
+public:
typedef HT head_type;
typedef null_type tail_type;
@@ -386,14 +426,20 @@
template <class HT2>
cons( const cons<HT2, null_type>& u ) : head(u.head) {}
+ template <class HT2>
+ cons( BOOST_RV_REF_2_TEMPL_ARGS(cons, HT2, null_type) u ) : head(::boost::move(u.head)) {}
template <class HT2>
- cons& operator=(const cons<HT2, null_type>& u )
+ cons& operator=(BOOST_COPY_ASSIGN_REF_2_TEMPL_ARGS(cons, HT2, null_type) u )
{ head = u.head; return *this; }
+ template <class HT2>
+ cons& operator=(BOOST_RV_REF_2_TEMPL_ARGS(cons, HT2, null_type) u )
+ { head = ::boost::move(u.head); return *this; }
// must define assignment operator explicitely, implicit version
// is illformed if HT is a reference
- cons& operator=(const cons& u) { head = u.head; return *this; }
+ cons& operator=(BOOST_COPY_ASSIGN_REF(cons) u) { head = u.head; return *this; }
+ cons& operator=(BOOST_RV_REF(cons) u) { head = ::boost::move(u.head); return *this; }
template <int N>
typename access_traits<
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