]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/coroutine/example/asymmetric/layout.cpp
2 // Copyright Nat Goodspeed 2013.
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)
13 #include <boost/assign/list_of.hpp>
14 #include <boost/bind.hpp>
15 #include <boost/coroutine/all.hpp>
16 #include <boost/range.hpp>
20 ~FinalEOL() { std::cout
<< std::endl
; }
23 void layout(boost::coroutines::asymmetric_coroutine
<std::string
>::pull_type
& in
, int num
, int width
)
25 // Finish the last line when we leave by whatever means
28 // Pull values from upstream, lay them out 'num' to a line
31 for (int i
= 0; i
< num
; ++i
)
33 // when we exhaust the input, stop
37 std::cout
<< std::setw(width
) << in
.get();
38 // now that we've handled this item, advance to next
41 // after 'num' items, line break
42 std::cout
<< std::endl
;
46 int main(int argc
, char *argv
[])
48 std::vector
<std::string
> words
= boost::assign::list_of
65 boost::coroutines::asymmetric_coroutine
<std::string
>::push_type
writer(
66 boost::bind(layout
, _1
, 5, 15));
68 std::copy(boost::begin(words
), boost::end(words
), boost::begin(writer
));
70 std::cout
<< "\nDone" << std::endl
;