]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/thread/example/lambda_future.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / thread / example / lambda_future.cpp
CommitLineData
7c673cae
FG
1// Copyright (C) 2013 Vicente Botet
2//
3// Distributed under the Boost Software License, Version 1.0. (See accompanying
4// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6
7#include <boost/config.hpp>
8#if ! defined BOOST_NO_CXX11_DECLTYPE
9#define BOOST_RESULT_OF_USE_DECLTYPE
10#endif
11
12#define BOOST_THREAD_VERSION 4
13//#define BOOST_THREAD_USES_LOG
14#define BOOST_THREAD_USES_LOG_THREAD_ID
15
16#include <boost/thread/detail/log.hpp>
17#include <boost/thread/future.hpp>
18#include <boost/assert.hpp>
19#include <string>
20#include <iostream>
21
22#if defined BOOST_THREAD_PROVIDES_FUTURE_CONTINUATION \
b32b8144 23 && ! defined BOOST_NO_CXX11_LAMBDAS && ! (defined BOOST_MSVC && _MSC_VER < 1800) // works since msvc-12.0
7c673cae 24
b32b8144
FG
25#ifdef BOOST_MSVC
26#pragma warning(disable: 4127) // conditional expression is constant
27#endif
7c673cae
FG
28
29int main()
30{
31 const int number_of_tests = 100;
32 BOOST_THREAD_LOG << "<MAIN" << BOOST_THREAD_END_LOG;
33
34 for (int i=0; i< number_of_tests; i++)
35 try
36 {
37 {
38 boost::future<int> f1 = boost::async(boost::launch::async, []() {return 123;});
39 int result = f1.get();
40 BOOST_THREAD_LOG << "f1 " << result << BOOST_THREAD_END_LOG;
41 }
42 {
43 boost::future<int> f1 = boost::async(boost::launch::async, []() {return 123;});
44 boost::future<int> f2 = f1.then([](boost::future<int> f) {return 2*f.get(); });
45 int result = f2.get();
46 BOOST_THREAD_LOG << "f2 " << result << BOOST_THREAD_END_LOG;
47 }
48#if ! defined BOOST_NO_CXX14_GENERIC_LAMBDAS
49 {
50 boost::future<int> f1 = boost::async(boost::launch::async, []() {return 123;});
51 boost::future<int> f2 = f1.then([](auto f) {return 2*f.get(); });
52 int result = f2.get();
53 BOOST_THREAD_LOG << "f2 " << result << BOOST_THREAD_END_LOG;
54 }
55#endif
56 }
57 catch (std::exception& ex)
58 {
59 std::cout << "ERRORRRRR "<<ex.what() << "" << std::endl;
60 BOOST_THREAD_LOG << "ERRORRRRR "<<ex.what() << "" << BOOST_THREAD_END_LOG;
61 return 1;
62 }
63 catch (...)
64 {
65 std::cout << " ERRORRRRR exception thrown" << std::endl;
66 BOOST_THREAD_LOG << " ERRORRRRR exception thrown" << BOOST_THREAD_END_LOG;
67 return 2;
68 }
69 BOOST_THREAD_LOG << "MAIN>" << BOOST_THREAD_END_LOG;
70 return 0;
71}
72#else
73
b32b8144
FG
74//#warning "This test is not supported in this configuration, either because Bosst.Thread has been configured to don't support continuations, the compiler doesn't provides lambdas or because they are buggy as for MSV versions < msvc-12.0"
75
7c673cae
FG
76int main()
77{
78 return 0;
79}
80#endif