diff --git a/include/boost/coroutine/detail/symmetric_coroutine_impl.hpp b/include/boost/coroutine/detail/symmetric_coroutine_impl.hpp index 7d52d04..916a48b 100644 --- a/include/boost/coroutine/detail/symmetric_coroutine_impl.hpp +++ b/include/boost/coroutine/detail/symmetric_coroutine_impl.hpp @@ -145,22 +145,22 @@ public: } template< typename X > - R * yield_to( symmetric_coroutine_impl< X > * other, X x) + R * yield_to( symmetric_coroutine_impl< X > * other, X const& x) { BOOST_ASSERT( ! is_complete() ); BOOST_ASSERT( ! other->is_complete() ); - typename symmetric_coroutine_impl< X >::param_type to( & x); + typename symmetric_coroutine_impl< X >::param_type to( const_cast< X * >( & x) ); return yield_to_( other, & to); } template< typename X > - R * yield_to( symmetric_coroutine_impl< X & > * other, X & x) + R * yield_to( symmetric_coroutine_impl< X & > * other, X const& x) { BOOST_ASSERT( ! is_complete() ); BOOST_ASSERT( ! other->is_complete() ); - typename symmetric_coroutine_impl< X & >::param_type to( & x); + typename symmetric_coroutine_impl< X & >::param_type to( const_cast< X * >( & x) ); return yield_to_( other, & to); } @@ -281,22 +281,22 @@ public: } template< typename X > - R * yield_to( symmetric_coroutine_impl< X > * other, X x) + R * yield_to( symmetric_coroutine_impl< X > * other, X const& x) { BOOST_ASSERT( ! is_complete() ); BOOST_ASSERT( ! other->is_complete() ); - typename symmetric_coroutine_impl< X >::param_type to( & x); + typename symmetric_coroutine_impl< X >::param_type to( const_cast< X * >( & x) ); return yield_to_( other, & to); } template< typename X > - R * yield_to( symmetric_coroutine_impl< X & > * other, X & x) + R * yield_to( symmetric_coroutine_impl< X & > * other, X const& x) { BOOST_ASSERT( ! is_complete() ); BOOST_ASSERT( ! other->is_complete() ); - typename symmetric_coroutine_impl< X & >::param_type to( & x); + typename symmetric_coroutine_impl< X & >::param_type to( const_cast< X * >( & x) ); return yield_to_( other, & to); } @@ -418,12 +418,22 @@ public: } template< typename X > - void yield_to( symmetric_coroutine_impl< X & > * other, X & x) + void yield_to( symmetric_coroutine_impl< X > * other, X const& x) { BOOST_ASSERT( ! is_complete() ); BOOST_ASSERT( ! other->is_complete() ); - typename symmetric_coroutine_impl< X & >::param_type to( & x); + typename symmetric_coroutine_impl< X >::param_type to( const_cast< X * >( & x) ); + yield_to_( other, & to); + } + + template< typename X > + void yield_to( symmetric_coroutine_impl< X & > * other, X const& x) + { + BOOST_ASSERT( ! is_complete() ); + BOOST_ASSERT( ! other->is_complete() ); + + typename symmetric_coroutine_impl< X & >::param_type to( const_cast< X * >( & x) ); yield_to_( other, & to); } diff --git a/include/boost/coroutine/detail/symmetric_coroutine_yield.hpp b/include/boost/coroutine/detail/symmetric_coroutine_yield.hpp index 621ded2..3079621 100644 --- a/include/boost/coroutine/detail/symmetric_coroutine_yield.hpp +++ b/include/boost/coroutine/detail/symmetric_coroutine_yield.hpp @@ -12,6 +12,8 @@ #include #include #include +#include +#include #include #include @@ -38,6 +40,8 @@ private: typedef parameters< R > param_type; typedef symmetric_coroutine_impl< R > impl_type; + struct dummy {}; + BOOST_MOVABLE_BUT_NOT_COPYABLE( symmetric_coroutine_yield) impl_type * impl_; @@ -86,7 +90,11 @@ public: } template< typename Coro > - symmetric_coroutine_yield & operator()( Coro & other, typename Coro::value_type & x) + symmetric_coroutine_yield & operator()( Coro & other, typename Coro::value_type const& x, + typename disable_if< + is_same< typename Coro::value_type, void >, + dummy* + >::type = 0) { BOOST_ASSERT( other); @@ -95,7 +103,11 @@ public: } template< typename Coro > - symmetric_coroutine_yield & operator()( Coro & other) + symmetric_coroutine_yield & operator()( Coro & other, + typename enable_if< + is_same< typename Coro::value_type, void >, + dummy* + >::type = 0) { BOOST_ASSERT( other); @@ -171,7 +183,11 @@ public: } template< typename Coro > - symmetric_coroutine_yield & operator()( Coro & other, typename Coro::value_type & x) + symmetric_coroutine_yield & operator()( Coro & other, typename Coro::value_type const& x, + typename disable_if< + is_same< typename Coro::value_type, void >, + dummy* + >::type = 0) { BOOST_ASSERT( other); @@ -180,7 +196,11 @@ public: } template< typename Coro > - symmetric_coroutine_yield & operator()( Coro & other) + symmetric_coroutine_yield & operator()( Coro & other, + typename enable_if< + is_same< typename Coro::value_type, void >, + dummy* + >::type = 0) { BOOST_ASSERT( other); @@ -206,6 +226,8 @@ private: typedef parameters< void > param_type; typedef symmetric_coroutine_impl< void > impl_type; + struct dummy {}; + BOOST_MOVABLE_BUT_NOT_COPYABLE( symmetric_coroutine_yield) impl_type * impl_; @@ -245,7 +267,11 @@ public: } template< typename Coro > - symmetric_coroutine_yield & operator()( Coro & other, typename Coro::value_type & x) + symmetric_coroutine_yield & operator()( Coro & other, typename Coro::value_type const& x, + typename disable_if< + is_same< typename Coro::value_type, void >, + dummy* + >::type = 0) { BOOST_ASSERT( other); @@ -254,7 +280,11 @@ public: } template< typename Coro > - symmetric_coroutine_yield & operator()( Coro & other) + symmetric_coroutine_yield & operator()( Coro & other, + typename enable_if< + is_same< typename Coro::value_type, void >, + dummy* + >::type = 0) { BOOST_ASSERT( other);