diff --git a/doc/Jamfile.v2 b/doc/Jamfile.v2 index b9d1707..f02d4d4 100644 --- a/doc/Jamfile.v2 +++ b/doc/Jamfile.v2 @@ -9,9 +9,6 @@ import boostbook ; import quickbook ; import modules ; -path-constant images_location : html ; -path-constant here : . ; - boostbook coro : coro.qbk @@ -29,7 +26,4 @@ boostbook coro toc.max.depth=3 # How far down we go with TOC's generate.section.toc.level=10 - pdf:img.src.path=$(images_location)/ ; - - diff --git a/include/boost/coroutine/detail/coroutine_op.hpp b/include/boost/coroutine/detail/coroutine_op.hpp index 6611202..ba37d7a 100644 --- a/include/boost/coroutine/detail/coroutine_op.hpp +++ b/include/boost/coroutine/detail/coroutine_op.hpp @@ -123,11 +123,11 @@ struct coroutine_op< Signature, D, Result, 0 > { return const_cast< optional< Result > & >( val_).get_ptr(); } }; - class const_iterator : public std::iterator< std::input_iterator_tag, typename remove_reference< const Result >::type > + class const_iterator : public std::iterator< std::input_iterator_tag, const typename remove_reference< Result >::type > { private: - D * dp_; - optional< const Result > val_; + D * dp_; + optional< Result > val_; void fetch_() { @@ -152,15 +152,15 @@ struct coroutine_op< Signature, D, Result, 0 > } public: - typedef typename iterator::pointer pointer_t; - typedef typename iterator::reference reference_t; + typedef typename const_iterator::pointer pointer_t; + typedef typename const_iterator::reference reference_t; const_iterator() : dp_( 0), val_() {} - explicit const_iterator( D * dp) : - dp_( dp), val_() + explicit const_iterator( D const* dp) : + dp_( const_cast< D * >( dp) ), val_() { fetch_(); } const_iterator( const_iterator const& other) : diff --git a/test/test_coroutine.cpp b/test/test_coroutine.cpp index 46f0a03..9854a0f 100644 --- a/test/test_coroutine.cpp +++ b/test/test_coroutine.cpp @@ -42,6 +42,7 @@ typedef coro::coroutine< int(int) > coro_int_int; typedef coro::coroutine< int*(int*) > coro_ptr; typedef coro::coroutine< int const&(int const&) > coro_ref; typedef coro::coroutine< boost::tuple(int&,int&) > coro_tuple; +typedef coro::coroutine< const int *() > coro_const_int_ptr_void; struct X : private boost::noncopyable { @@ -200,6 +201,12 @@ void f18( coro_int_int::caller_type & self) } } +void f19( coro_const_int_ptr_void::caller_type & self, std::vector< const int * > & vec) +{ + BOOST_FOREACH( const int * ptr, vec) + { self( ptr); } +} + void test_move() { { @@ -410,16 +417,51 @@ void test_exceptions() void test_output_iterator() { - std::vector< int > vec; - coro_int_void coro( f16); - BOOST_FOREACH( int i, coro) - { vec.push_back( i); } - BOOST_CHECK_EQUAL( ( std::size_t)5, vec.size() ); - BOOST_CHECK_EQUAL( ( int)1, vec[0] ); - BOOST_CHECK_EQUAL( ( int)2, vec[1] ); - BOOST_CHECK_EQUAL( ( int)3, vec[2] ); - BOOST_CHECK_EQUAL( ( int)4, vec[3] ); - BOOST_CHECK_EQUAL( ( int)5, vec[4] ); + { + std::vector< int > vec; + coro_int_void coro( f16); + BOOST_FOREACH( int i, coro) + { vec.push_back( i); } + BOOST_CHECK_EQUAL( ( std::size_t)5, vec.size() ); + BOOST_CHECK_EQUAL( ( int)1, vec[0] ); + BOOST_CHECK_EQUAL( ( int)2, vec[1] ); + BOOST_CHECK_EQUAL( ( int)3, vec[2] ); + BOOST_CHECK_EQUAL( ( int)4, vec[3] ); + BOOST_CHECK_EQUAL( ( int)5, vec[4] ); + } + { + std::vector< int > vec; + coro_int_void coro( f16); + coro_int_void::iterator e = boost::end( coro); + for ( + coro_int_void::iterator i = boost::begin( coro); + i != e; ++i) + { vec.push_back( * i); } + BOOST_CHECK_EQUAL( ( std::size_t)5, vec.size() ); + BOOST_CHECK_EQUAL( ( int)1, vec[0] ); + BOOST_CHECK_EQUAL( ( int)2, vec[1] ); + BOOST_CHECK_EQUAL( ( int)3, vec[2] ); + BOOST_CHECK_EQUAL( ( int)4, vec[3] ); + BOOST_CHECK_EQUAL( ( int)5, vec[4] ); + } + { + int i1 = 1, i2 = 2, i3 = 3; + std::vector< const int* > vec_in; + vec_in.push_back( & i1); + vec_in.push_back( & i2); + vec_in.push_back( & i3); + std::vector< const int* > vec_out; + coro_const_int_ptr_void coro( boost::bind( f19, _1, boost::ref( vec_in) ) ); + coro_const_int_ptr_void::const_iterator e = boost::const_end( coro); + for ( + coro_const_int_ptr_void::const_iterator i = boost::const_begin( coro); + i != e; ++i) + { vec_out.push_back( * i); } + BOOST_CHECK_EQUAL( ( std::size_t)3, vec_out.size() ); + BOOST_CHECK_EQUAL( & i1, vec_out[0] ); + BOOST_CHECK_EQUAL( & i2, vec_out[1] ); + BOOST_CHECK_EQUAL( & i3, vec_out[2] ); + } } void test_input_iterator() @@ -465,7 +507,6 @@ void test_post() BOOST_CHECK( ! coro); } - boost::unit_test::test_suite * init_unit_test_suite( int, char* []) { boost::unit_test::test_suite * test =