Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r83089 - in sandbox/tuple-move: boost/tuple/detail libs/tuple/test
From: adam.wulkiewicz_at_[hidden]
Date: 2013-02-22 14:10:45


Author: awulkiew
Date: 2013-02-22 14:10:44 EST (Fri, 22 Feb 2013)
New Revision: 83089
URL: http://svn.boost.org/trac/boost/changeset/83089

Log:
Fixed issue with assigning of const object in c++98
Text files modified:
   sandbox/tuple-move/boost/tuple/detail/tuple_basic.hpp | 16 ++++++++++----
   sandbox/tuple-move/libs/tuple/test/tuple_move.cpp | 44 ++++++++++++++++++++++++++++-----------
   2 files changed, 42 insertions(+), 18 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-22 14:10:44 EST (Fri, 22 Feb 2013)
@@ -258,9 +258,11 @@
 struct cons {
 
 #ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
-
   cons& operator=(cons & t)
   { this->operator=(static_cast<const ::boost::rv<cons> &>(const_cast<const cons &>(t))); return *this;}
+ cons& operator=(const cons & t)
+ { this->operator=(static_cast<const ::boost::rv<cons> &>(t)); return *this;}
+
   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;}
@@ -268,7 +270,6 @@
   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;}
 
- // needed for const templated other
   template <class HT2, class TT2>
   cons& operator=(const cons<HT2, TT2> & t)
   { this->operator=(static_cast<const ::boost::rv<cons<HT2, TT2> > &>(t)); return *this;}
@@ -280,7 +281,6 @@
   { return *static_cast< ::boost::rv<cons>* >(this); }
   operator const ::boost::rv<cons>&() const
   { return *static_cast<const ::boost::rv<cons>* >(this); }
-
 #endif
 
   typedef HT head_type;
@@ -395,11 +395,12 @@
 #ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
   cons& operator=(cons & t)
   { this->operator=(static_cast<const ::boost::rv<cons> &>(const_cast<const cons &>(t))); return *this;}
+ cons& operator=(const cons & t)
+ { this->operator=(static_cast<const ::boost::rv<cons> &>(t)); return *this;}
+
   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;}
-
- // needed for const templated other
   template <class HT2>
   cons& operator=(const cons<HT2, null_type> & t)
   { this->operator=(static_cast<const ::boost::rv<cons<HT2, null_type> > &>(t)); return *this;}
@@ -546,6 +547,11 @@
   BOOST_COPYABLE_AND_MOVABLE(tuple)
 #ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
 public:
+ tuple& operator=(const tuple & t) {
+ this->operator=(static_cast<const ::boost::rv<tuple> &>(t));
+ 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=(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;

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-22 14:10:44 EST (Fri, 22 Feb 2013)
@@ -32,15 +32,10 @@
     state_type last;
 };
 
-struct foo
-{
- boost::tuple<int> t;
-};
-
 template <typename T>
-struct foot
+struct foo
 {
- boost::tuple<T> t;
+ T t;
 };
 
 int test_main(int, char* [])
@@ -231,20 +226,43 @@
     BOOST_CHECK(get<0>(ti).last_op() == cm::copy_assign);
     ti = boost::move(cpf);
     BOOST_CHECK(get<0>(ti).last_op() == cm::copy_assign);
-
- {
- foo a, b;
- a = b;
- }
     
     {
- foot<cm> a, b;
+ foo< boost::tuple<cm> > a, b;
         a = b;
         BOOST_CHECK(get<0>(a.t).last_op() == cm::copy_assign);
         a = boost::move(b);
+#ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
+ BOOST_CHECK(get<0>(a.t).last_op() == cm::copy_assign);
+#else
+ BOOST_CHECK(get<0>(a.t).last_op() == cm::move_assign);
+#endif
+ a = foo< boost::tuple<cm> >();
+#ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
         BOOST_CHECK(get<0>(a.t).last_op() == cm::copy_assign);
+#else
+ BOOST_CHECK(get<0>(a.t).last_op() == cm::move_assign);
+#endif
     }
     
+ {
+ foo< cons<cm, cons<int, null_type> > > a, b;
+ cm & cm_ref = boost::tuples::get<0>(a.t);
+ a = b;
+ BOOST_CHECK(cm_ref.last_op() == cm::copy_assign);
+ a = boost::move(b);
+#ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
+ BOOST_CHECK(cm_ref.last_op() == cm::copy_assign);
+#else
+ BOOST_CHECK(cm_ref.last_op() == cm::move_assign);
+#endif
+ a = foo< cons<cm, cons<int, null_type> > >();
+#ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
+ BOOST_CHECK(cm_ref.last_op() == cm::copy_assign);
+#else
+ BOOST_CHECK(cm_ref.last_op() == cm::move_assign);
+#endif
+ }
 
     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