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