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)
7 #include <boost/coroutine/all.hpp>
15 #include <boost/assign/list_of.hpp>
16 #include <boost/bind.hpp>
17 #include <boost/range.hpp>
21 ~FinalEOL() { std::cout << std::endl; }
24 void layout(boost::coroutines::asymmetric_coroutine<std::string>::pull_type& in, int num, int width)
26 // Finish the last line when we leave by whatever means
29 // Pull values from upstream, lay them out 'num' to a line
32 for (int i = 0; i < num; ++i)
34 // when we exhaust the input, stop
38 std::cout << std::setw(width) << in.get();
39 // now that we've handled this item, advance to next
42 // after 'num' items, line break
43 std::cout << std::endl;
47 int main(int argc, char *argv[])
49 std::vector<std::string> words = boost::assign::list_of
66 boost::coroutines::asymmetric_coroutine<std::string>::push_type writer(
67 boost::bind(layout, _1, 5, 15));
69 std::copy(boost::begin(words), boost::end(words), boost::begin(writer));
71 std::cout << "\nDone" << std::endl;