Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r83253 - in sandbox/type_erasure: boost/type_erasure boost/type_erasure/detail libs/type_erasure/test
From: steven_at_[hidden]
Date: 2013-03-02 16:48:28


Author: steven_watanabe
Date: 2013-03-02 16:48:27 EST (Sat, 02 Mar 2013)
New Revision: 83253
URL: http://svn.boost.org/trac/boost/changeset/83253

Log:
Support rvalue anys as arguments to call.
Text files modified:
   sandbox/type_erasure/boost/type_erasure/call.hpp | 28 ++++++++++++++++++++++++++++
   sandbox/type_erasure/boost/type_erasure/detail/access.hpp | 31 +++++++++++++++++++++++++++++++
   sandbox/type_erasure/boost/type_erasure/detail/adapt_to_vtable.hpp | 32 ++++++++++++++++++++++++++++++--
   sandbox/type_erasure/boost/type_erasure/detail/check_call.hpp | 6 +-----
   sandbox/type_erasure/boost/type_erasure/detail/rebind_placeholders.hpp | 13 +++++++++++++
   sandbox/type_erasure/boost/type_erasure/detail/storage.hpp | 2 +-
   sandbox/type_erasure/libs/type_erasure/test/test_callable.cpp | 20 ++++++++++++++++++--
   7 files changed, 122 insertions(+), 10 deletions(-)

Modified: sandbox/type_erasure/boost/type_erasure/call.hpp
==============================================================================
--- sandbox/type_erasure/boost/type_erasure/call.hpp (original)
+++ sandbox/type_erasure/boost/type_erasure/call.hpp 2013-03-02 16:48:27 EST (Sat, 02 Mar 2013)
@@ -128,6 +128,34 @@
 
 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
 
+template<class Concept, class T>
+::boost::type_erasure::detail::storage&&
+convert_arg(any_base<any<Concept, T> >&& arg, boost::mpl::true_)
+{
+ return ::boost::type_erasure::detail::access::data(std::move(arg));
+}
+
+template<class Concept, class T>
+::boost::type_erasure::detail::storage&&
+convert_arg(any_base<any<Concept, T&&> >& arg, boost::mpl::true_)
+{
+ return ::boost::type_erasure::detail::access::data(arg);
+}
+
+template<class Concept, class T>
+::boost::type_erasure::detail::storage&&
+convert_arg(param<Concept, T>&& arg, boost::mpl::true_)
+{
+ return ::boost::type_erasure::detail::access::data(std::move(arg));
+}
+
+template<class Concept, class T>
+::boost::type_erasure::detail::storage&&
+convert_arg(param<Concept, T&&>& arg, boost::mpl::true_)
+{
+ return ::boost::type_erasure::detail::access::data(arg);
+}
+
 template<class T>
 T&& convert_arg(T&& arg, boost::mpl::false_) { return std::forward<T>(arg); }
 

Modified: sandbox/type_erasure/boost/type_erasure/detail/access.hpp
==============================================================================
--- sandbox/type_erasure/boost/type_erasure/detail/access.hpp (original)
+++ sandbox/type_erasure/boost/type_erasure/detail/access.hpp 2013-03-02 16:48:27 EST (Sat, 02 Mar 2013)
@@ -87,6 +87,37 @@
     {
         return arg._impl.data;
     }
+
+#ifndef BOOST_NO_RVALUE_REFERENCES
+
+ template<class Derived>
+ static ::boost::type_erasure::detail::storage&&
+ data(::boost::type_erasure::any_base<Derived>&& arg)
+ {
+ return static_cast<Derived&&>(arg).data;
+ }
+ template<class Concept, class T>
+ static ::boost::type_erasure::detail::storage&&
+ data(::boost::type_erasure::any_base< ::boost::type_erasure::any<Concept, T&&> >& arg)
+ {
+ return static_cast< ::boost::type_erasure::any<Concept, T&&>&>(arg).data;
+ }
+
+ template<class Concept, class T>
+ static ::boost::type_erasure::detail::storage&&
+ data(::boost::type_erasure::param<Concept, T>&& arg)
+ {
+ return std::move(arg._impl.data);
+ }
+ template<class Concept, class T>
+ static ::boost::type_erasure::detail::storage&&
+ data(::boost::type_erasure::param<Concept, T&&>& arg)
+ {
+ return std::move(arg._impl.data);
+ }
+
+#endif
+
 };
 
 }

Modified: sandbox/type_erasure/boost/type_erasure/detail/adapt_to_vtable.hpp
==============================================================================
--- sandbox/type_erasure/boost/type_erasure/detail/adapt_to_vtable.hpp (original)
+++ sandbox/type_erasure/boost/type_erasure/detail/adapt_to_vtable.hpp 2013-03-02 16:48:27 EST (Sat, 02 Mar 2013)
@@ -83,6 +83,20 @@
>::type type;
 };
 
+#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
+
+template<class T>
+struct replace_param_for_vtable<T&&>
+{
+ typedef typename ::boost::mpl::if_<
+ ::boost::type_erasure::is_placeholder<typename ::boost::remove_cv<T>::type>,
+ ::boost::type_erasure::detail::storage&&,
+ T&&
+ >::type type;
+};
+
+#endif
+
 template<class T>
 struct replace_result_for_vtable
 {
@@ -113,6 +127,20 @@
>::type type;
 };
 
+#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
+
+template<class T>
+struct replace_result_for_vtable<T&&>
+{
+ typedef typename ::boost::mpl::if_<
+ ::boost::type_erasure::is_placeholder<typename ::boost::remove_cv<T>::type>,
+ ::boost::type_erasure::detail::storage&&,
+ T&&
+ >::type type;
+};
+
+#endif
+
 template<class Sig>
 struct get_vtable_signature;
 
@@ -158,7 +186,7 @@
     static R value(T... arg)
     {
         return PrimitiveConcept::apply(
- ::boost::type_erasure::detail::extract<U>(arg)...);
+ ::boost::type_erasure::detail::extract<U>(std::forward<T>(arg))...);
     }
 };
 
@@ -171,7 +199,7 @@
         ::boost::type_erasure::detail::storage result;
         typename ::boost::remove_reference<R2>::type* p =
             ::boost::addressof(
- PrimitiveConcept::apply(::boost::type_erasure::detail::extract<U>(arg)...));
+ PrimitiveConcept::apply(::boost::type_erasure::detail::extract<U>(std::forward<T>(arg))...));
         result.data = const_cast<void*>(static_cast<const void*>(p));
         return result;
     }

Modified: sandbox/type_erasure/boost/type_erasure/detail/check_call.hpp
==============================================================================
--- sandbox/type_erasure/boost/type_erasure/detail/check_call.hpp (original)
+++ sandbox/type_erasure/boost/type_erasure/detail/check_call.hpp 2013-03-02 16:48:27 EST (Sat, 02 Mar 2013)
@@ -63,11 +63,7 @@
 struct qualified_placeholder<T&&, typename T::_boost_type_erasure_is_any>
 {
     typedef typename ::boost::type_erasure::placeholder_of<T>::type placeholder;
- typedef typename ::boost::remove_reference<placeholder>::type unref;
- typedef typename ::boost::mpl::if_< ::boost::is_reference<placeholder>,
- unref&,
- unref&&
- >::type type;
+ typedef placeholder&& type;
 };
 
 #endif

Modified: sandbox/type_erasure/boost/type_erasure/detail/rebind_placeholders.hpp
==============================================================================
--- sandbox/type_erasure/boost/type_erasure/detail/rebind_placeholders.hpp (original)
+++ sandbox/type_erasure/boost/type_erasure/detail/rebind_placeholders.hpp 2013-03-02 16:48:27 EST (Sat, 02 Mar 2013)
@@ -70,6 +70,19 @@
>::type& type;
 };
 
+#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
+
+template<class T, class Bindings>
+struct rebind_placeholders_in_argument<T&&, Bindings>
+{
+ typedef typename ::boost::type_erasure::detail::rebind_placeholders_in_argument<
+ T,
+ Bindings
+ >::type&& type;
+};
+
+#endif
+
 template<class T, class Bindings>
 struct rebind_placeholders_in_argument<const T, Bindings>
 {

Modified: sandbox/type_erasure/boost/type_erasure/detail/storage.hpp
==============================================================================
--- sandbox/type_erasure/boost/type_erasure/detail/storage.hpp (original)
+++ sandbox/type_erasure/boost/type_erasure/detail/storage.hpp 2013-03-02 16:48:27 EST (Sat, 02 Mar 2013)
@@ -55,7 +55,7 @@
 template<class T>
 T extract(storage&& arg)
 {
- return static_cast<T>(*static_cast<typename ::boost::remove_reference<T>::type*>(arg.data));
+ return std::move(*static_cast<typename ::boost::remove_reference<T>::type*>(arg.data));
 }
 
 #endif

Modified: sandbox/type_erasure/libs/type_erasure/test/test_callable.cpp
==============================================================================
--- sandbox/type_erasure/libs/type_erasure/test/test_callable.cpp (original)
+++ sandbox/type_erasure/libs/type_erasure/test/test_callable.cpp 2013-03-02 16:48:27 EST (Sat, 02 Mar 2013)
@@ -388,9 +388,25 @@
         callable<void(int&&)>
> test_concept;
     any<test_concept> f(&f_rv);
-
+
+ f_rv_value = 1;
     f(2);
- BOOST_CHECK_EQUAL(f_rv_value, 2);
+ BOOST_CHECK_EQUAL(f_rv_value, 3);
+}
+
+BOOST_AUTO_TEST_CASE(test_rvalue_any)
+{
+ typedef ::boost::mpl::vector<
+ common<>,
+ common<_a>,
+ callable<void(_a&&)>
+ > test_concept;
+
+ tuple<test_concept, _self, _a> t1(&f_rv, 3);
+ any<test_concept> x1(get<0>(t1));
+ f_rv_value = 1;
+ x1(std::move(get<1>(t1)));
+ BOOST_CHECK_EQUAL(f_rv_value, 4);
 }
 
 #endif


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