Imported Upstream version 1.64.0
[platform/upstream/boost.git] / libs / context / example / callcc / fibonacci.cpp
1
2 //          Copyright Oliver Kowalke 2016.
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 #include <memory>
10
11 #include <boost/context/continuation.hpp>
12
13 namespace ctx = boost::context;
14
15 int main() {
16     ctx::continuation c=ctx::callcc(
17         [](ctx::continuation && c){
18             int a=0;
19             int b=1;
20             for(;;){
21                 c=c.resume(a);
22                 auto next=a+b;
23                 a=b;
24                 b=next;
25             }
26             return std::move( c);
27         });
28     for ( int j = 0; j < 10; ++j) {
29         std::cout << c.get_data<int>() << " ";
30         c=c.resume();
31     }
32     std::cout << std::endl;
33     std::cout << "main: done" << std::endl;
34 }