]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/coroutine/example/asymmetric/power.cpp
2 // Copyright Oliver Kowalke 2009.
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
7 #include <boost/coroutine/all.hpp>
12 #include <boost/bind.hpp>
13 #include <boost/foreach.hpp>
14 #include <boost/range.hpp>
16 void power( boost::coroutines::asymmetric_coroutine
< int >::push_type
& sink
, int number
, int exponent
)
20 while ( counter
++ < exponent
)
22 result
= result
* number
;
30 std::cout
<< "using range functions" << std::endl
;
31 boost::coroutines::asymmetric_coroutine
< int >::pull_type
source( boost::bind( power
, _1
, 2, 8) );
32 boost::coroutines::asymmetric_coroutine
< int >::pull_type::iterator
e( boost::end( source
) );
33 for ( boost::coroutines::asymmetric_coroutine
< int >::pull_type::iterator
i( boost::begin( source
) );
35 std::cout
<< * i
<< " ";
39 std::cout
<< "\nusing BOOST_FOREACH" << std::endl
;
40 boost::coroutines::asymmetric_coroutine
< int >::pull_type
source( boost::bind( power
, _1
, 2, 8) );
41 BOOST_FOREACH( int i
, source
)
42 { std::cout
<< i
<< " "; }
45 std::cout
<< "\nDone" << std::endl
;