Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r82760 - in trunk: boost/coroutine libs/coroutine/example
From: oliver.kowalke_at_[hidden]
Date: 2013-02-06 20:26:28


Author: olli
Date: 2013-02-06 11:59:17 EST (Wed, 06 Feb 2013)
New Revision: 82760
URL: http://svn.boost.org/trac/boost/changeset/82760

Log:
coroutine: support C++11 range-for

Text files modified:
   trunk/boost/coroutine/coroutine.hpp | 12 ++++++++++
   trunk/libs/coroutine/example/power.cpp | 46 ++++++++++++++++++++++++++++++++++++++-
   2 files changed, 56 insertions(+), 2 deletions(-)

Modified: trunk/boost/coroutine/coroutine.hpp
==============================================================================
--- trunk/boost/coroutine/coroutine.hpp (original)
+++ trunk/boost/coroutine/coroutine.hpp 2013-02-06 11:59:17 EST (Wed, 06 Feb 2013)
@@ -1386,6 +1386,18 @@
 range_end( coroutine< Signature > const&)
 { return typename coroutine< Signature >::const_iterator(); }
 
+template< typename Signature >
+inline
+typename coroutine< Signature >::iterator
+begin( coroutine< Signature > & c)
+{ return boost::begin( c); }
+
+template< typename Signature >
+inline
+typename coroutine< Signature >::iterator
+end( coroutine< Signature > & c)
+{ return boost::end( c); }
+
 }
 
 template< typename Signature >

Modified: trunk/libs/coroutine/example/power.cpp
==============================================================================
--- trunk/libs/coroutine/example/power.cpp (original)
+++ trunk/libs/coroutine/example/power.cpp 2013-02-06 11:59:17 EST (Wed, 06 Feb 2013)
@@ -12,8 +12,8 @@
 #include <boost/range.hpp>
 #include <boost/coroutine/all.hpp>
 
-typedef boost::coroutines::coroutine< int() > coro1_t;
-typedef boost::coroutines::coroutine< void( int) > coro2_t;
+typedef boost::coroutines::coroutine< int() > coro1_t;
+typedef boost::coroutines::coroutine< void( int) > coro2_t;
 typedef boost::range_iterator< coro1_t >::type iterator_t;
 
 void power( coro2_t & c, int number, int exponent)
@@ -48,3 +48,45 @@
 
     return EXIT_SUCCESS;
 }
+#if 0
+int main()
+{
+ {
+ std::cout << "using range functions" << std::endl;
+ boost::coroutines::coroutine< int() > c(
+ [&]( boost::coroutines::coroutine< void( int) > &c) {
+ int counter = 0;
+ int result = 1;
+ while ( counter++ < 8)
+ {
+ result = result * 2;
+ c( result);
+ }
+ });
+ iterator_t e( boost::end( c) );
+ for ( iterator_t i( boost::begin( c) ); i != e; ++i)
+ std::cout << * i << " ";
+ }
+
+ {
+ std::cout << "\nusing BOOST_FOREACH" << std::endl;
+ boost::coroutines::coroutine< int() > c(
+ [&]( boost::coroutines::coroutine< void( int) > &c) {
+ int counter = 0;
+ int result = 1;
+ while ( counter++ < 8)
+ {
+ result = result * 2;
+ c( result);
+ }
+ });
+ for ( int i : c) {
+ std::cout << i << " ";
+ }
+ }
+
+ std::cout << "\nDone" << std::endl;
+
+ return EXIT_SUCCESS;
+}
+#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