]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/thread/test/test_10964.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / thread / test / test_10964.cpp
1 // Copyright (C) 2015 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 #define BOOST_THREAD_VERSION 4
7 #include <boost/config.hpp>
8 #if ! defined BOOST_NO_CXX11_DECLTYPE
9 #define BOOST_RESULT_OF_USE_DECLTYPE
10 #endif
11 #define BOOST_THREAD_PROVIDES_EXECUTORS
12
13 #include <boost/thread/future.hpp>
14 #include <boost/static_assert.hpp>
15 #include <cassert>
16 #include <boost/thread/executors/basic_thread_pool.hpp>
17
18 struct TestCallback
19 {
20 typedef boost::future<void> result_type;
21
22 result_type operator()(boost::future<void> future) const
23 {
24 std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
25 assert(future.is_ready());
26 std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
27 future.wait();
28 std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
29 return boost::make_ready_future();
30 }
31
32 result_type operator()(boost::future<boost::future<void> > future) const
33 {
34 std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
35 assert(future.is_ready());
36 std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
37 assert(future.get().is_ready());
38 std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
39 //boost::future<void> ff = future.get();
40
41 return boost::make_ready_future();
42 }
43 result_type operator()(boost::shared_future<void> future) const
44 {
45 std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
46 assert(future.is_ready());
47 std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
48 future.wait();
49 std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
50 return boost::make_ready_future();
51 }
52
53 result_type operator()(boost::shared_future<boost::future<void> > future) const
54 {
55 std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
56 assert(future.is_ready());
57 std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
58 assert(future.get().is_ready());
59 std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
60 //boost::future<void> ff = future.get();
61
62 return boost::make_ready_future();
63 }
64 };
65
66 void p1()
67 {
68 }
69
70 int main()
71 {
72 const int number_of_tests = 2;
73 (void)(number_of_tests);
74
75 #if ! defined BOOST_NO_CXX11_DECLTYPE && ! defined BOOST_NO_CXX11_AUTO_DECLARATIONS
76 std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
77 {
78 auto f1 = boost::make_ready_future().then(TestCallback());
79 BOOST_STATIC_ASSERT(std::is_same<decltype(f1), boost::future<boost::future<void> > >::value);
80 f1.wait();
81 }
82 std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
83 for (int i=0; i< number_of_tests; i++)
84 {
85 auto f1 = boost::make_ready_future().then(TestCallback());
86 std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
87 BOOST_STATIC_ASSERT(std::is_same<decltype(f1), boost::future<boost::future<void> > >::value);
88 std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
89 auto f2 = f1.unwrap();
90 std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
91 BOOST_STATIC_ASSERT(std::is_same<decltype(f2), boost::future<void> >::value);
92 std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
93 f2.wait();
94 std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
95 }
96 std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
97 for (int i=0; i< number_of_tests; i++)
98 {
99 auto f1 = boost::make_ready_future().then(TestCallback());
100 BOOST_STATIC_ASSERT(std::is_same<decltype(f1), boost::future<boost::future<void> > >::value);
101 boost::future<void> f2 = f1.get();
102 }
103 std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
104 {
105 auto f1 = boost::make_ready_future().then(TestCallback());
106 BOOST_STATIC_ASSERT(std::is_same<decltype(f1), boost::future<boost::future<void> > >::value);
107 auto f3 = f1.then(TestCallback());
108 BOOST_STATIC_ASSERT(std::is_same<decltype(f3), boost::future<boost::future<void> > >::value);
109 f3.wait();
110 }
111 std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
112 for (int i=0; i< number_of_tests; i++)
113 {
114 auto f1 = boost::make_ready_future().then(TestCallback());
115 BOOST_STATIC_ASSERT(std::is_same<decltype(f1), boost::future<boost::future<void> > >::value);
116 auto f2 = f1.unwrap();
117 BOOST_STATIC_ASSERT(std::is_same<decltype(f2), boost::future<void> >::value);
118 auto f3 = f2.then(TestCallback());
119 BOOST_STATIC_ASSERT(std::is_same<decltype(f3), boost::future<boost::future<void> > >::value);
120 f3.wait();
121 }
122 std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
123 for (int i=0; i< number_of_tests; i++)
124 {
125 boost::make_ready_future().then(
126 TestCallback()).unwrap().then(TestCallback()).get();
127 }
128 std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
129 for (int i=0; i< number_of_tests; i++)
130 {
131 boost::future<void> f = boost::async(p1);
132 f.then(
133 TestCallback()).unwrap().then(TestCallback()).get();
134 }
135 std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
136 for (int i=0; i< number_of_tests; i++)
137 {
138 auto f1 = boost::make_ready_future().then(TestCallback());
139 BOOST_STATIC_ASSERT(std::is_same<decltype(f1), boost::future<boost::future<void> > >::value);
140 auto f3 = f1.then(TestCallback());
141 BOOST_STATIC_ASSERT(std::is_same<decltype(f3), boost::future<boost::future<void> > >::value);
142 f3.wait();
143 }
144 std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
145 for (int i=0; i< number_of_tests; i++)
146 {
147 boost::basic_thread_pool executor;
148 auto f1 = boost::make_ready_future().then(executor, TestCallback());
149 BOOST_STATIC_ASSERT(std::is_same<decltype(f1), boost::future<boost::future<void> > >::value);
150 auto f3 = f1.then(executor, TestCallback());
151 BOOST_STATIC_ASSERT(std::is_same<decltype(f3), boost::future<boost::future<void> > >::value);
152 f3.wait();
153 }
154 #if 1
155 std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
156 // fixme
157 for (int i=0; i< number_of_tests; i++)
158 {
159 boost::basic_thread_pool executor(2);
160
161 auto f1 = boost::make_ready_future().then(executor, TestCallback());
162 BOOST_STATIC_ASSERT(std::is_same<decltype(f1), boost::future<boost::future<void> > >::value);
163 std::cout << __FILE__ << "[" << __LINE__ << "] " << int(f1.valid()) << std::endl;
164 auto f2 = f1.unwrap();
165 std::cout << __FILE__ << "[" << __LINE__ << "] " << int(f2.valid()) << std::endl;
166
167 BOOST_STATIC_ASSERT(std::is_same<decltype(f2), boost::future<void> >::value);
168 auto f3 = f2.then(executor, TestCallback());
169 BOOST_STATIC_ASSERT(std::is_same<decltype(f3), boost::future<boost::future<void> > >::value);
170 f3.wait();
171 }
172 #endif
173 std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
174 for (int i=0; i< number_of_tests; i++)
175 {
176 boost::basic_thread_pool executor;
177
178 auto f1 = boost::make_ready_future().then(executor, TestCallback());
179 BOOST_STATIC_ASSERT(std::is_same<decltype(f1), boost::future<boost::future<void> > >::value);
180 auto f2 = f1.unwrap();
181 BOOST_STATIC_ASSERT(std::is_same<decltype(f2), boost::future<void> >::value);
182 auto f3 = f2.then(executor, TestCallback());
183 BOOST_STATIC_ASSERT(std::is_same<decltype(f3), boost::future<boost::future<void> > >::value);
184 f3.wait();
185 }
186 std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
187
188 #endif
189 return 0;
190 }