Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r86085 - in trunk: boost/type_erasure/detail libs/type_erasure/test
From: steven_at_[hidden]
Date: 2013-09-30 16:04:18


Author: steven_watanabe
Date: 2013-09-30 16:04:18 EDT (Mon, 30 Sep 2013)
New Revision: 86085
URL: http://svn.boost.org/trac/boost/changeset/86085

Log:
Handle construction from rvalue references.

Text files modified:
   trunk/boost/type_erasure/detail/storage.hpp | 20 ++++++++++++++++++++
   trunk/libs/type_erasure/test/test_construct.cpp | 18 ++++++++++++++++++
   2 files changed, 38 insertions(+), 0 deletions(-)

Modified: trunk/boost/type_erasure/detail/storage.hpp
==============================================================================
--- trunk/boost/type_erasure/detail/storage.hpp Mon Sep 30 15:23:49 2013 (r86084)
+++ trunk/boost/type_erasure/detail/storage.hpp 2013-09-30 16:04:18 EDT (Mon, 30 Sep 2013) (r86085)
@@ -11,7 +11,14 @@
 #ifndef BOOST_TYPE_ERASURE_DETAIL_STORAGE_HPP_INCLUDED
 #define BOOST_TYPE_ERASURE_DETAIL_STORAGE_HPP_INCLUDED
 
+#include <boost/config.hpp>
 #include <boost/type_traits/remove_reference.hpp>
+#include <boost/type_traits/remove_cv.hpp>
+
+#ifdef BOOST_MSVC
+#pragma warning(push)
+#pragma warning(disable:4521)
+#endif
 
 namespace boost {
 namespace type_erasure {
@@ -20,8 +27,17 @@
 struct storage
 {
     storage() {}
+#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
+ storage(storage& other) : data(other.data) {}
+ storage(const storage& other) : data(other.data) {}
+ storage(storage&& other) : data(other.data) {}
+ template<class T>
+ storage(T&& arg) : data(new typename remove_cv<
+ typename remove_reference<T>::type>::type(std::forward<T>(arg))) {}
+#else
     template<class T>
     storage(const T& arg) : data(new T(arg)) {}
+#endif
     void* data;
 };
 
@@ -64,4 +80,8 @@
 }
 }
 
+#ifdef BOOST_MSVC
+#pragma warning(pop)
+#endif
+
 #endif

Modified: trunk/libs/type_erasure/test/test_construct.cpp
==============================================================================
--- trunk/libs/type_erasure/test/test_construct.cpp Mon Sep 30 15:23:49 2013 (r86084)
+++ trunk/libs/type_erasure/test/test_construct.cpp 2013-09-30 16:04:18 EDT (Mon, 30 Sep 2013) (r86085)
@@ -1015,6 +1015,24 @@
 
 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
 
+struct move_only
+{
+ explicit move_only(int i) : value(i) {}
+ move_only(move_only&& other) : value(other.value) { other.value = 0; }
+ int value;
+private:
+ move_only(const move_only&);
+};
+
+BOOST_AUTO_TEST_CASE(test_move_only)
+{
+ typedef ::boost::mpl::vector<destructible<>, typeid_<> > test_concept;
+ move_only source(2);
+ any<test_concept> x(std::move(source));
+ BOOST_CHECK_EQUAL(source.value, 0);
+ BOOST_CHECK_EQUAL(any_cast<move_only&>(x).value, 2);
+}
+
 BOOST_AUTO_TEST_CASE(test_copy_from_rref)
 {
     typedef ::boost::mpl::vector<common<> > test_concept;


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