|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r83092 - in sandbox/tuple-move: boost/tuple/detail libs/tuple/test
From: adam.wulkiewicz_at_[hidden]
Date: 2013-02-22 20:51:04
Author: awulkiew
Date: 2013-02-22 20:51:04 EST (Fri, 22 Feb 2013)
New Revision: 83092
URL: http://svn.boost.org/trac/boost/changeset/83092
Log:
move_if_no_ref_imp() added for convinience.
Added in other tuples::cont move ctors.
Additional tests of tuples storing references added.
Text files modified:
sandbox/tuple-move/boost/tuple/detail/tuple_basic.hpp | 35 +++++++++++-------
sandbox/tuple-move/libs/tuple/test/tuple_move.cpp | 76 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 97 insertions(+), 14 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 20:51:04 EST (Fri, 22 Feb 2013)
@@ -258,23 +258,26 @@
template <bool Cond, class T1, class T2> struct if_c { typedef T1 type; };
template <class T1, class T2> struct if_c<false, T1, T2> { typedef T2 type; };
-template <bool IsRef> struct ref_or_move {
- template <class T> inline static
- T & apply(T & t) { return t; }
+template <class T, bool IsRef> struct move_if_no_ref_impl {
+ typedef T& result_type;
+ inline static T & apply(T & t) { return t; }
};
-template <> struct ref_or_move<false> {
- template <class T> inline static
+template <class T> struct move_if_no_ref_impl<T, false> {
+ typedef typename
#ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
- typename if_c<
- ::boost::has_move_emulation_enabled<T>::value, rv<T>&, T&
- >::type
+ if_c< ::boost::has_move_emulation_enabled<T>::value, rv<T>&, T& >::type
#else
- typename ::boost::remove_reference<T>::type &&
+ ::boost::remove_reference<T>::type &&
#endif
- apply(T & t) { return ::boost::move(t); }
+ result_type;
+ inline static result_type apply(T & t) { return ::boost::move(t); }
};
+template <class S, class T> inline
+typename move_if_no_ref_impl<T, ::boost::is_reference<S>::value>::result_type
+move_if_no_ref(T & t) { return move_if_no_ref_impl<T, ::boost::is_reference<S>::value>::apply(t); }
+
} // detail
template <class HT, class TT>
@@ -359,12 +362,14 @@
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)) {}
+ cons( BOOST_RV_REF_2_TEMPL_ARGS(cons, HT2, TT2) u )
+ : head(detail::move_if_no_ref<typename cons<HT2, TT2>::stored_head_type>(u.head))
+ , tail(::boost::move(u.tail)) {}
// implicit version may be deleted in C++11
cons( const cons& u ) : head(u.head), tail(u.tail) {}
cons( BOOST_RV_REF(cons) u )
- : head(detail::ref_or_move< ::boost::is_reference<stored_head_type>::value >::apply(u.head))
+ : head(detail::move_if_no_ref<stored_head_type>(u.head))
, tail(::boost::move(u.tail)) {}
template <class HT2, class TT2>
@@ -476,11 +481,13 @@
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)) {}
+ cons( BOOST_RV_REF_2_TEMPL_ARGS(cons, HT2, null_type) u )
+ // here ::boost::move() might be used because if HT is a reference HT2 must be the same so the other ctor will be called
+ : head(detail::move_if_no_ref<typename cons<HT2, null_type>::stored_head_type>(u.head)) {}
// implicit version may be deleted in C++11
cons( const cons& u ) : head(u.head) {}
- cons( BOOST_RV_REF(cons) u ) : head(detail::ref_or_move< ::boost::is_reference<stored_head_type>::value >::apply(u.head)) {}
+ cons( BOOST_RV_REF(cons) u ) : head(detail::move_if_no_ref<stored_head_type>(u.head)) {}
template <class HT2>
cons& operator=(BOOST_COPY_ASSIGN_REF_2_TEMPL_ARGS(cons, HT2, null_type) u )
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 20:51:04 EST (Fri, 22 Feb 2013)
@@ -264,6 +264,82 @@
//#endif
}
+ {
+ int dummy_t = 10;
+ int dummy_c = 20;
+
+ cons<int, cons<int&, null_type> > cir( cons<int, cons<int&, null_type> >(0, dummy_c) );
+ BOOST_CHECK(&boost::tuples::get<1>(cir) == &dummy_c);
+
+ tuple<int, int&> tir = tuple<int, int&>(0, dummy_t);
+ BOOST_CHECK(&boost::get<1>(tir) == &dummy_t);
+
+ cir = cons<int, cons<int&, null_type> >(0, dummy_c);
+ BOOST_CHECK(&boost::tuples::get<1>(cir) == &dummy_c);
+
+ tir = tuple<int, int&>(0, dummy_t);
+ BOOST_CHECK(&boost::get<1>(tir) == &dummy_t);
+
+ cir = cir;
+ cir = boost::move(cir);
+ tir = boost::move(cir);
+ BOOST_CHECK(dummy_t = dummy_c);
+ tir = boost::move(tir);
+ tir = tir;
+ }
+
+ {
+ int dummy_t = 10;
+ int dummy_c = 20;
+
+ cons<int, cons<int&, null_type> > cir( cons<float, cons<int&, null_type> >(0.0f, dummy_c) );
+ BOOST_CHECK(&boost::tuples::get<1>(cir) == &dummy_c);
+
+ tuple<int, int&> tir = tuple<float, int&>(0.0f, dummy_t);
+ BOOST_CHECK(&boost::get<1>(tir) == &dummy_t);
+
+ cir = cons<float, cons<int&, null_type> >(0.0f, dummy_c);
+ BOOST_CHECK(&boost::tuples::get<1>(cir) == &dummy_c);
+
+ tir = tuple<float, int&>(0.0f, dummy_t);
+ BOOST_CHECK(&boost::get<1>(tir) == &dummy_t);
+
+ cons<float, cons<int&, null_type> > cir2(0.0f, dummy_c);
+ tuple<float, int&> tir2(0.0f, dummy_t);
+ cir = cir2;
+ cir = boost::move(cir2);
+ tir = boost::move(cir2);
+ BOOST_CHECK(dummy_t == dummy_c);
+ tir = boost::move(tir2);
+ tir = tir2;
+ }
+
+ {
+ int dummy_t = 10;
+ int dummy_c = 20;
+
+ cons<int&, cons<int, null_type> > cir( cons<int&, cons<float, null_type> >(dummy_c, 0.0f) );
+ BOOST_CHECK(&boost::tuples::get<0>(cir) == &dummy_c);
+
+ tuple<int&, int> tir = tuple<int&, float>(dummy_t, 0.0f);
+ BOOST_CHECK(&boost::get<0>(tir) == &dummy_t);
+
+ cir = cons<int&, cons<float, null_type> >(dummy_c, 0.0f);
+ BOOST_CHECK(&boost::tuples::get<0>(cir) == &dummy_c);
+
+ tir = tuple<int&, float>(dummy_t, 0.0f);
+ BOOST_CHECK(&boost::get<0>(tir) == &dummy_t);
+
+ cons<int&, cons<float, null_type> > cir2(dummy_c, 0.0f);
+ tuple<int&, float> tir2(dummy_t, 0.0f);
+ cir = cir2;
+ cir = boost::move(cir2);
+ tir = boost::move(cir2);
+ BOOST_CHECK(dummy_t == dummy_c);
+ tir = boost::move(tir2);
+ tir = tir2;
+ }
+
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