|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r85159 - in trunk: boost/variant/detail libs/variant/test
From: antoshkka_at_[hidden]
Date: 2013-07-25 09:19:50
Author: apolukhin
Date: 2013-07-25 09:19:50 EDT (Thu, 25 Jul 2013)
New Revision: 85159
URL: http://svn.boost.org/trac/boost/changeset/85159
Log:
Get rid of Boost.Variant hand written non-usable move emulation and use Boost.Move instead (refs #7601). This commit does not make Boost.Variant use move emulated assignments in all situations, but at least removes duplicate/non-working code and makes sure that Boost.Variant is able to work with boost::move (one step closer to full support of rvalue references emulations).
Text files modified:
trunk/boost/variant/detail/move.hpp | 92 ---------------------------------------
trunk/libs/variant/test/rvalue_test.cpp | 83 +++++++++++++++++++++--------------
2 files changed, 52 insertions(+), 123 deletions(-)
Modified: trunk/boost/variant/detail/move.hpp
==============================================================================
--- trunk/boost/variant/detail/move.hpp Thu Jul 25 04:56:08 2013 (r85158)
+++ trunk/boost/variant/detail/move.hpp 2013-07-25 09:19:50 EDT (Thu, 25 Jul 2013) (r85159)
@@ -24,100 +24,12 @@
#include "boost/config.hpp"
#include "boost/detail/workaround.hpp"
-#include "boost/mpl/if.hpp"
-#include "boost/type_traits/is_base_and_derived.hpp"
+#include "boost/move/move.hpp"
namespace boost {
namespace detail { namespace variant {
-//////////////////////////////////////////////////////////////////////////
-// forward declares
-//
-// NOTE: Incomplete until (if?) Boost.Move becomes part of Boost.
-//
-template <typename Deriving> class moveable;
-template <typename T> class move_source;
-template <typename T> class move_return;
-
-namespace detail {
-
-// (detail) moveable_tag
-//
-// Concrete type from which moveable<T> derives.
-//
-// TODO: Move into moveable_fwd.hpp and define has_move_constructor.
-//
-template <typename Deriving>
-struct moveable_tag
-{
-};
-
-} // namespace detail
-
-//////////////////////////////////////////////////////////////////////////
-// function template move
-//
-// Takes a T& and returns, if T derives moveable<T>, a move_source<T> for
-// the object; else, returns the T&.
-//
-
-namespace detail {
-
-// (detail) class template move_type
-//
-// Metafunction that, given moveable T, provides move_source<T>, else T&.
-//
-template <typename T>
-struct move_type
-{
-public: // metafunction result
-
- typedef typename mpl::if_<
- is_base_and_derived<detail::moveable_tag<T>, T>
- , move_source<T>
- , T&
- >::type type;
-
-};
-
-} // namespace detail
-
-#ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
-
-template <typename T>
-inline
- typename detail::move_type<T>::type
-move(T& source)
-{
- typedef typename detail::move_type<T>::type
- move_t;
-
- return move_t(source);
-}
-
-#else
-
-using std::move;
-
-#endif
-
-//////////////////////////////////////////////////////////////////////////
-// class template return_t
-//
-// Metafunction that, given moveable T, provides move_return<T>, else T.
-//
-template <typename T>
-struct return_t
-{
-public: // metafunction result
-
- typedef typename mpl::if_<
- is_base_and_derived<moveable<T>, T>
- , move_return<T>
- , T
- >::type type;
-
-};
+using boost::move;
//////////////////////////////////////////////////////////////////////////
// function template move_swap
Modified: trunk/libs/variant/test/rvalue_test.cpp
==============================================================================
--- trunk/libs/variant/test/rvalue_test.cpp Thu Jul 25 04:56:08 2013 (r85158)
+++ trunk/libs/variant/test/rvalue_test.cpp 2013-07-25 09:19:50 EDT (Thu, 25 Jul 2013) (r85159)
@@ -15,31 +15,8 @@
#include "boost/variant.hpp"
#include "boost/type_traits/is_nothrow_move_assignable.hpp"
-// This test requires rvalue references support
+// Most part of tests from this file require rvalue references support
-#ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
-
-void run()
-{
- BOOST_CHECK(true);
-}
-
-void run1()
-{
- BOOST_CHECK(true);
-}
-
-void run_move_only()
-{
- BOOST_CHECK(true);
-}
-
-void run_moves_are_noexcept()
-{
- BOOST_CHECK(true);
-}
-
-#else
class move_copy_conting_class {
public:
@@ -47,11 +24,11 @@
static unsigned int copy_count;
move_copy_conting_class(){}
- move_copy_conting_class(move_copy_conting_class&&) {
+ move_copy_conting_class(BOOST_RV_REF(move_copy_conting_class) ) {
++ moves_count;
}
- move_copy_conting_class& operator=(move_copy_conting_class&&) {
+ move_copy_conting_class& operator=(BOOST_RV_REF(move_copy_conting_class) ) {
++ moves_count;
return *this;
}
@@ -59,7 +36,7 @@
move_copy_conting_class(const move_copy_conting_class&) {
++ copy_count;
}
- move_copy_conting_class& operator=(const move_copy_conting_class&) {
+ move_copy_conting_class& operator=(BOOST_COPY_ASSIGN_REF(move_copy_conting_class) ) {
++ copy_count;
return *this;
}
@@ -68,6 +45,46 @@
unsigned int move_copy_conting_class::moves_count = 0;
unsigned int move_copy_conting_class::copy_count = 0;
+#ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
+
+void run()
+{
+ // Making sure that internals of Boost.Move do not interfere with
+ // internals of Boost.Variant and in case of C++03 or C++98 compilation
+ // is still possible.
+ typedef boost::variant<int, move_copy_conting_class> variant_I_type;
+ variant_I_type v1, v2;
+ v1 = move_copy_conting_class();
+ v2 = v1;
+ v2 = boost::move(v1);
+ v1.swap(v2);
+
+ move_copy_conting_class val;
+ v2 = boost::move(val);
+ v2 = 10;
+
+ variant_I_type v3(boost::move(val));
+ variant_I_type v4(boost::move(v1));
+}
+
+void run1()
+{
+ BOOST_CHECK(true);
+}
+
+void run_move_only()
+{
+ BOOST_CHECK(true);
+}
+
+void run_moves_are_noexcept()
+{
+ BOOST_CHECK(true);
+}
+
+#else
+
+
void run()
{
typedef boost::variant<int, move_copy_conting_class> variant_I_type;
@@ -92,7 +109,7 @@
move_copy_conting_class::moves_count = 0;
move_copy_conting_class::copy_count = 0;
- v2 = static_cast<variant_I_type&&>(v1);
+ v2 = boost::move(v1);
// Assuring that `move_copy_conting_class` in v1 was moved at least once and was not copied
BOOST_CHECK(move_copy_conting_class::moves_count != 0);
BOOST_CHECK(move_copy_conting_class::copy_count == 0);
@@ -100,7 +117,7 @@
v1 = move_copy_conting_class();
move_copy_conting_class::moves_count = 0;
move_copy_conting_class::copy_count = 0;
- v2 = static_cast<variant_I_type&&>(v1);
+ v2 = boost::move(v1);
// Assuring that `move_copy_conting_class` in v1 was moved at least once and was not copied
BOOST_CHECK(move_copy_conting_class::moves_count != 0);
BOOST_CHECK(move_copy_conting_class::copy_count == 0);
@@ -116,19 +133,19 @@
variant_II_type v3;
move_copy_conting_class::moves_count = 0;
move_copy_conting_class::copy_count = 0;
- v1 = static_cast<variant_II_type&&>(v3);
+ v1 = boost::move(v3);
// Assuring that `move_copy_conting_class` in v3 was moved at least once (v1 and v3 have different types)
BOOST_CHECK(move_copy_conting_class::moves_count != 0);
move_copy_conting_class::moves_count = 0;
move_copy_conting_class::copy_count = 0;
- v2 = static_cast<variant_I_type&&>(v1);
+ v2 = boost::move(v1);
// Assuring that `move_copy_conting_class` in v1 was moved at least once (v1 and v3 have different types)
BOOST_CHECK(move_copy_conting_class::moves_count != 0);
move_copy_conting_class::moves_count = 0;
move_copy_conting_class::copy_count = 0;
- variant_I_type v5(static_cast<variant_I_type&&>(v1));
+ variant_I_type v5(boost::move(v1));
// Assuring that `move_copy_conting_class` in v1 was moved at least once and was not copied
BOOST_CHECK(move_copy_conting_class::moves_count != 0);
BOOST_CHECK(move_copy_conting_class::copy_count == 0);
@@ -148,7 +165,7 @@
move_copy_conting_class c1;
typedef boost::variant<int, move_copy_conting_class> variant_I_type;
- variant_I_type v1(static_cast<move_copy_conting_class&&>(c1));
+ variant_I_type v1(boost::move(c1));
// Assuring that `move_copy_conting_class` was not copyied
BOOST_CHECK(move_copy_conting_class::copy_count == 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