Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r83072 - in sandbox/tuple-move: boost/tuple/detail libs/tuple/test
From: adam.wulkiewicz_at_[hidden]
Date: 2013-02-21 18:17:20


Author: awulkiew
Date: 2013-02-21 18:17:19 EST (Thu, 21 Feb 2013)
New Revision: 83072
URL: http://svn.boost.org/trac/boost/changeset/83072

Log:
Added tuple move and copy assignment, added tests for all handled classes, fixed errors
Text files modified:
   sandbox/tuple-move/boost/tuple/detail/tuple_basic.hpp | 34 ++++++++-
   sandbox/tuple-move/libs/tuple/test/tuple_move.cpp | 128 +++++++++++++++++++++++++++++++++++----
   2 files changed, 143 insertions(+), 19 deletions(-)

Modified: sandbox/tuple-move/boost/tuple/detail/tuple_basic.hpp
==============================================================================
--- sandbox/tuple-move/boost/tuple/detail/tuple_basic.hpp (original)
+++ sandbox/tuple-move/boost/tuple/detail/tuple_basic.hpp 2013-02-21 18:17:19 EST (Thu, 21 Feb 2013)
@@ -545,6 +545,7 @@
 {
   BOOST_COPYABLE_AND_MOVABLE(tuple)
 #ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
+public:
   template <class U0, class U1, class U2, class U3, class U4, class U5, class U6, class U7, class U8, class U9>
   tuple& operator=(tuple<U0, U1, U2, U3, U4, U5, U6, U7, U8, U9> & t) {
     typedef tuple<U0, U1, U2, U3, U4, U5, U6, U7, U8, U9> Tup;
@@ -567,10 +568,10 @@
 
   template <class U1, class U2>
   tuple& operator=(std::pair<U1, U2> & t)
- { this->operator=(static_cast<const ::boost::rv<std::pair<T1, T2> > &>(const_cast<const std::pair<T1, T2> &>(t))); return *this;}
+ { this->operator=(static_cast<const ::boost::rv<std::pair<U1, U2> > &>(const_cast<const std::pair<U1, U2> &>(t))); return *this;}
   template <class U1, class U2>
   tuple& operator=(const std::pair<U1, U2> & t)
- { this->operator=(static_cast<const ::boost::rv<std::pair<T1, T2> > &>(t)); return *this;}
+ { this->operator=(static_cast<const ::boost::rv<std::pair<U1, U2> > &>(t)); return *this;}
 #endif
 
 public:
@@ -676,7 +677,7 @@
   {}
   template <class U0, class U1, class U2, class U3, class U4, class U5, class U6, class U7, class U8, class U9>
   tuple(BOOST_RV_REF_BEG tuple<U0, U1, U2, U3, U4, U5, U6, U7, U8, U9> BOOST_RV_REF_END p)
- : inherited(boost::move(static_cast<typename tuple<U0, U1, U2, U3, U4, U5, U6, U7, U8, U9>::inherited &>(p)))
+ : inherited(::boost::move(static_cast<typename tuple<U0, U1, U2, U3, U4, U5, U6, U7, U8, U9>::inherited &>(p)))
   {}
 
   // implicit version may be deleted in C++11
@@ -688,6 +689,27 @@
   template<class U1, class U2>
   tuple(BOOST_RV_REF_2_TEMPL_ARGS(cons, U1, U2) p) : inherited(boost::move(p)) {}
 
+ template <class U0, class U1, class U2, class U3, class U4, class U5, class U6, class U7, class U8, class U9>
+ tuple& operator=(BOOST_COPY_ASSIGN_REF_BEG tuple<U0, U1, U2, U3, U4, U5, U6, U7, U8, U9> BOOST_COPY_ASSIGN_REF_END k) {
+ inherited::operator=(static_cast<const typename tuple<U0, U1, U2, U3, U4, U5, U6, U7, U8, U9>::inherited &>(k));
+ return *this;
+ }
+ template <class U0, class U1, class U2, class U3, class U4, class U5, class U6, class U7, class U8, class U9>
+ tuple& operator=(BOOST_RV_REF_BEG tuple<U0, U1, U2, U3, U4, U5, U6, U7, U8, U9> BOOST_RV_REF_END k) {
+ inherited::operator=(::boost::move(static_cast<typename tuple<U0, U1, U2, U3, U4, U5, U6, U7, U8, U9>::inherited &>(k)));
+ return *this;
+ }
+
+ // implicit version may be deleted in C++11
+ tuple& operator=(BOOST_COPY_ASSIGN_REF(tuple) k) {
+ inherited::operator=(static_cast<const inherited &>(k));
+ return *this;
+ }
+ tuple& operator=(BOOST_RV_REF(tuple) k) {
+ inherited::operator=(::boost::move(static_cast<inherited &>(k)));
+ return *this;
+ }
+
   template <class U1, class U2>
   tuple& operator=(BOOST_COPY_ASSIGN_REF_2_TEMPL_ARGS(cons, U1, U2) k) {
     inherited::operator=(k);
@@ -695,7 +717,7 @@
   }
   template <class U1, class U2>
   tuple& operator=(BOOST_RV_REF_2_TEMPL_ARGS(cons, U1, U2) k) {
- inherited::operator=(boost::move(k));
+ inherited::operator=(::boost::move(k));
     return *this;
   }
 
@@ -709,8 +731,8 @@
   template <class U1, class U2>
   tuple& operator=(BOOST_RV_REF_2_TEMPL_ARGS(std::pair, U1, U2) k) {
     BOOST_STATIC_ASSERT(length<tuple>::value == 2);// check_length = 2
- this->head = boost::move(k.first);
- this->tail.head = boost::move(k.second);
+ this->head = ::boost::move(k.first);
+ this->tail.head = ::boost::move(k.second);
     return *this;
   }
 

Modified: sandbox/tuple-move/libs/tuple/test/tuple_move.cpp
==============================================================================
--- sandbox/tuple-move/libs/tuple/test/tuple_move.cpp (original)
+++ sandbox/tuple-move/libs/tuple/test/tuple_move.cpp 2013-02-21 18:17:19 EST (Thu, 21 Feb 2013)
@@ -19,10 +19,10 @@
     enum state_type {def_ctor, copy_ctor, move_ctor, copy_assign, move_assign};
     
     cm() : last(def_ctor) {}
- cm(const cm & o) : last(copy_ctor) {}
- cm(BOOST_RV_REF(cm) o) : last(move_ctor) {}
- cm & operator=(BOOST_COPY_ASSIGN_REF(cm) o) { last = copy_assign; return *this; }
- cm & operator=(BOOST_RV_REF(cm) o) { last = move_assign; return *this; }
+ cm(const cm &) : last(copy_ctor) {}
+ cm(BOOST_RV_REF(cm)) : last(move_ctor) {}
+ cm & operator=(BOOST_COPY_ASSIGN_REF(cm)) { last = copy_assign; return *this; }
+ cm & operator=(BOOST_RV_REF(cm)) { last = move_assign; return *this; }
 
     state_type last_op() { return last; }
 
@@ -35,12 +35,35 @@
     using namespace boost;
     using namespace boost::tuples;
 
+ std::pair<cm, int> pi;
+ std::pair<cm, float> pf;
+ const std::pair<cm, int> cpi;
+ const std::pair<cm, float> cpf;
     cons<cm, cons<int, null_type> > ci;
     cons<cm, cons<float, null_type> > cf;
     const cons<cm, cons<int, null_type> > cci;
     const cons<cm, cons<float, null_type> > ccf;
+ tuple<cm, int> ti;
+ tuple<cm, float> tf;
+ const tuple<cm, int> cti;
+ const tuple<cm, float> ctf;
+
+ bool pi_move_enabled =
+#ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
+ !boost::enable_move_utility_emulation< std::pair<cm, int> >::value ||
+ boost::has_move_emulation_enabled< std::pair<cm, int> >::value;
+#else
+ true;
+#endif
+ bool pf_move_enabled =
+#ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
+ !boost::enable_move_utility_emulation< std::pair<cm, float> >::value ||
+ boost::has_move_emulation_enabled< std::pair<cm, float> >::value;
+#else
+ true;
+#endif
 
- // tuples::cons ctor
+ // tuples::cons( tuples::cons )
     cons<cm, cons<int, null_type> > cc1(ci);
     BOOST_CHECK(get<0>(cc1).last_op() == cm::copy_ctor);
     cons<cm, cons<int, null_type> > cc2(boost::move(ci));
@@ -58,7 +81,7 @@
     cons<cm, cons<int, null_type> > cc8(boost::move(ccf));
     BOOST_CHECK(get<0>(cc8).last_op() == cm::copy_ctor);
 
- // tuples::cons assignment
+ // tuples::cons = tuples::cons
     ci = ci;
     BOOST_CHECK(get<0>(ci).last_op() == cm::copy_assign);
     ci = boost::move(ci);
@@ -76,7 +99,31 @@
     ci = boost::move(ccf);
     BOOST_CHECK(get<0>(ci).last_op() == cm::copy_assign);
 
- // tuple ctor taking tuples::cons
+ // tuples::cons = std::pair
+ ci = pi;
+ BOOST_CHECK(get<0>(ci).last_op() == cm::copy_assign);
+ ci = boost::move(pi);
+ if ( pi_move_enabled )
+ BOOST_CHECK(get<0>(ci).last_op() == cm::move_assign);
+ else
+ BOOST_CHECK(get<0>(ci).last_op() == cm::copy_assign);
+ ci = pf;
+ BOOST_CHECK(get<0>(ci).last_op() == cm::copy_assign);
+ ci = boost::move(pf);
+ if ( pf_move_enabled )
+ BOOST_CHECK(get<0>(ci).last_op() == cm::move_assign);
+ else
+ BOOST_CHECK(get<0>(ci).last_op() == cm::copy_assign);
+ ci = cpi;
+ BOOST_CHECK(get<0>(ci).last_op() == cm::copy_assign);
+ ci = boost::move(cpi);
+ BOOST_CHECK(get<0>(ci).last_op() == cm::copy_assign);
+ ci = cpf;
+ BOOST_CHECK(get<0>(ci).last_op() == cm::copy_assign);
+ ci = boost::move(cpf);
+ BOOST_CHECK(get<0>(ci).last_op() == cm::copy_assign);
+
+ // tuple( tuples::cons )
     tuple<cm, int> tt1(ci);
     BOOST_CHECK(get<0>(tt1).last_op() == cm::copy_ctor);
     tuple<cm, int> tt2(move(ci));
@@ -94,12 +141,7 @@
     tuple<cm, int> tt8(move(ccf));
     BOOST_CHECK(get<0>(tt8).last_op() == cm::copy_ctor);
 
- tuple<cm, int> ti;
- tuple<cm, float> tf;
- const tuple<cm, int> cti;
- const tuple<cm, float> ctf;
-
- // tuple ctor taking tuple
+ // tuple( tuple )
     tuple<cm, int> tt9(ti);
     BOOST_CHECK(get<0>(tt9).last_op() == cm::copy_ctor);
     tuple<cm, int> tt10(move(ti));
@@ -117,5 +159,65 @@
     tuple<cm, int> tt16(move(ctf));
     BOOST_CHECK(get<0>(tt16).last_op() == cm::copy_ctor);
 
+ // tuple = tuple
+ ti = ti;
+ BOOST_CHECK(get<0>(ti).last_op() == cm::copy_assign);
+ ti = boost::move(ti);
+ BOOST_CHECK(get<0>(ti).last_op() == cm::move_assign);
+ ti = tf;
+ BOOST_CHECK(get<0>(ti).last_op() == cm::copy_assign);
+ ti = boost::move(tf);
+ BOOST_CHECK(get<0>(ti).last_op() == cm::move_assign);
+ ti = cti;
+ BOOST_CHECK(get<0>(ti).last_op() == cm::copy_assign);
+ ti = boost::move(cti);
+ BOOST_CHECK(get<0>(ti).last_op() == cm::copy_assign);
+ ti = ctf;
+ BOOST_CHECK(get<0>(ti).last_op() == cm::copy_assign);
+ ti = boost::move(ctf);
+ BOOST_CHECK(get<0>(ti).last_op() == cm::copy_assign);
+
+ // tuple = tuples::cons
+ ti = ci;
+ BOOST_CHECK(get<0>(ti).last_op() == cm::copy_assign);
+ ti = boost::move(ci);
+ BOOST_CHECK(get<0>(ti).last_op() == cm::move_assign);
+ ti = cf;
+ BOOST_CHECK(get<0>(ti).last_op() == cm::copy_assign);
+ ti = boost::move(cf);
+ BOOST_CHECK(get<0>(ti).last_op() == cm::move_assign);
+ ti = cci;
+ BOOST_CHECK(get<0>(ti).last_op() == cm::copy_assign);
+ ti = boost::move(cci);
+ BOOST_CHECK(get<0>(ti).last_op() == cm::copy_assign);
+ ti = ccf;
+ BOOST_CHECK(get<0>(ti).last_op() == cm::copy_assign);
+ ti = boost::move(ccf);
+ BOOST_CHECK(get<0>(ti).last_op() == cm::copy_assign);
+
+ // tuple = std::pair
+ ti = pi;
+ BOOST_CHECK(get<0>(ti).last_op() == cm::copy_assign);
+ ti = boost::move(pi);
+ if ( pi_move_enabled )
+ BOOST_CHECK(get<0>(ti).last_op() == cm::move_assign);
+ else
+ BOOST_CHECK(get<0>(ti).last_op() == cm::copy_assign);
+ ti = pf;
+ BOOST_CHECK(get<0>(ti).last_op() == cm::copy_assign);
+ ti = boost::move(pf);
+ if ( pf_move_enabled )
+ BOOST_CHECK(get<0>(ti).last_op() == cm::move_assign);
+ else
+ BOOST_CHECK(get<0>(ti).last_op() == cm::copy_assign);
+ ti = cpi;
+ BOOST_CHECK(get<0>(ti).last_op() == cm::copy_assign);
+ ti = boost::move(cpi);
+ BOOST_CHECK(get<0>(ti).last_op() == cm::copy_assign);
+ ti = cpf;
+ BOOST_CHECK(get<0>(ti).last_op() == cm::copy_assign);
+ ti = boost::move(cpf);
+ BOOST_CHECK(get<0>(ti).last_op() == cm::copy_assign);
+
     return 0;
 }


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