]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/coroutine/example/asymmetric/fibonacci.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / coroutine / example / asymmetric / fibonacci.cpp
1
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)
6
7 #include <cstdlib>
8 #include <iostream>
9
10 #include <boost/range.hpp>
11 #include <boost/coroutine/all.hpp>
12
13 void fibonacci( boost::coroutines::asymmetric_coroutine< int >::push_type & sink)
14 {
15 int first = 1, second = 1;
16 sink( first);
17 sink( second);
18 while ( true)
19 {
20 int third = first + second;
21 first = second;
22 second = third;
23 sink( third);
24 }
25 }
26
27 int main()
28 {
29 boost::coroutines::asymmetric_coroutine< int >::pull_type source( fibonacci);
30 boost::range_iterator<
31 boost::coroutines::asymmetric_coroutine< int >::pull_type
32 >::type it( boost::begin( source) );
33 for ( int i = 0; i < 10; ++i)
34 {
35 std::cout << * it << " ";
36 ++it;
37 }
38
39 std::cout << "\nDone" << std::endl;
40
41 return EXIT_SUCCESS;
42 }