]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/coroutine2/example/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/coroutine2/all.hpp>
17 std::cout
<< std::endl
;
21 int main(int argc
,char* argv
[]){
24 std::vector
<std::string
> words
{
25 "peas", "porridge", "hot", "peas",
26 "porridge", "cold", "peas", "porridge",
27 "in", "the", "pot", "nine",
30 boost::coroutines2::coroutine
<std::string
>::push_type
writer(
31 [&](boost::coroutines2::coroutine
<std::string
>::pull_type
& in
){
32 // finish the last line when we leave by whatever means
34 // pull values from upstream, lay them out 'num' to a line
36 for(int i
=0;i
<num
;++i
){
37 // when we exhaust the input, stop
39 std::cout
<< std::setw(width
) << in
.get();
40 // now that we've handled this item, advance to next
43 // after 'num' items, line break
44 std::cout
<< std::endl
;
47 std::copy(begin(words
),end(words
),begin(writer
));
48 std::cout
<< "\nDone";