1 // Copyright (C) 2015 Vicente Botet
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)
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
11 #define BOOST_THREAD_PROVIDES_EXECUTORS
13 #include <boost/thread/future.hpp>
14 #include <boost/static_assert.hpp>
17 #include <boost/thread/executors/basic_thread_pool.hpp>
21 typedef boost::future
<void> result_type
;
23 result_type
operator()(boost::future
<void> future
) const
25 std::cout
<< __FILE__
<< "[" << __LINE__
<< "]" << std::endl
;
26 assert(future
.is_ready());
27 std::cout
<< __FILE__
<< "[" << __LINE__
<< "]" << std::endl
;
29 std::cout
<< __FILE__
<< "[" << __LINE__
<< "]" << std::endl
;
30 return boost::make_ready_future();
33 result_type
operator()(boost::future
<boost::future
<void> > future
) const
35 std::cout
<< __FILE__
<< "[" << __LINE__
<< "]" << std::endl
;
36 assert(future
.is_ready());
37 std::cout
<< __FILE__
<< "[" << __LINE__
<< "]" << std::endl
;
38 assert(future
.get().is_ready());
39 std::cout
<< __FILE__
<< "[" << __LINE__
<< "]" << std::endl
;
40 //boost::future<void> ff = future.get();
42 return boost::make_ready_future();
44 result_type
operator()(boost::shared_future
<void> future
) const
46 std::cout
<< __FILE__
<< "[" << __LINE__
<< "]" << std::endl
;
47 assert(future
.is_ready());
48 std::cout
<< __FILE__
<< "[" << __LINE__
<< "]" << std::endl
;
50 std::cout
<< __FILE__
<< "[" << __LINE__
<< "]" << std::endl
;
51 return boost::make_ready_future();
54 result_type
operator()(boost::shared_future
<boost::future
<void> > future
) const
56 std::cout
<< __FILE__
<< "[" << __LINE__
<< "]" << std::endl
;
57 assert(future
.is_ready());
58 std::cout
<< __FILE__
<< "[" << __LINE__
<< "]" << std::endl
;
59 assert(future
.get().is_ready());
60 std::cout
<< __FILE__
<< "[" << __LINE__
<< "]" << std::endl
;
61 //boost::future<void> ff = future.get();
63 return boost::make_ready_future();
73 const int number_of_tests
= 2;
74 (void)(number_of_tests
);
76 #if ! defined BOOST_NO_CXX11_DECLTYPE && ! defined BOOST_NO_CXX11_AUTO_DECLARATIONS
77 std::cout
<< __FILE__
<< "[" << __LINE__
<< "]" << std::endl
;
79 auto f1
= boost::make_ready_future().then(TestCallback());
80 BOOST_STATIC_ASSERT(std::is_same
<decltype(f1
), boost::future
<boost::future
<void> > >::value
);
83 std::cout
<< __FILE__
<< "[" << __LINE__
<< "]" << std::endl
;
84 for (int i
=0; i
< number_of_tests
; i
++)
86 auto f1
= boost::make_ready_future().then(TestCallback());
87 std::cout
<< __FILE__
<< "[" << __LINE__
<< "]" << std::endl
;
88 BOOST_STATIC_ASSERT(std::is_same
<decltype(f1
), boost::future
<boost::future
<void> > >::value
);
89 std::cout
<< __FILE__
<< "[" << __LINE__
<< "]" << std::endl
;
90 auto f2
= f1
.unwrap();
91 std::cout
<< __FILE__
<< "[" << __LINE__
<< "]" << std::endl
;
92 BOOST_STATIC_ASSERT(std::is_same
<decltype(f2
), boost::future
<void> >::value
);
93 std::cout
<< __FILE__
<< "[" << __LINE__
<< "]" << std::endl
;
95 std::cout
<< __FILE__
<< "[" << __LINE__
<< "]" << std::endl
;
97 std::cout
<< __FILE__
<< "[" << __LINE__
<< "]" << std::endl
;
98 for (int i
=0; i
< number_of_tests
; i
++)
100 auto f1
= boost::make_ready_future().then(TestCallback());
101 BOOST_STATIC_ASSERT(std::is_same
<decltype(f1
), boost::future
<boost::future
<void> > >::value
);
102 boost::future
<void> f2
= f1
.get();
104 std::cout
<< __FILE__
<< "[" << __LINE__
<< "]" << std::endl
;
106 auto f1
= boost::make_ready_future().then(TestCallback());
107 BOOST_STATIC_ASSERT(std::is_same
<decltype(f1
), boost::future
<boost::future
<void> > >::value
);
108 auto f3
= f1
.then(TestCallback());
109 BOOST_STATIC_ASSERT(std::is_same
<decltype(f3
), boost::future
<boost::future
<void> > >::value
);
112 std::cout
<< __FILE__
<< "[" << __LINE__
<< "]" << std::endl
;
113 for (int i
=0; i
< number_of_tests
; i
++)
115 auto f1
= boost::make_ready_future().then(TestCallback());
116 BOOST_STATIC_ASSERT(std::is_same
<decltype(f1
), boost::future
<boost::future
<void> > >::value
);
117 auto f2
= f1
.unwrap();
118 BOOST_STATIC_ASSERT(std::is_same
<decltype(f2
), boost::future
<void> >::value
);
119 auto f3
= f2
.then(TestCallback());
120 BOOST_STATIC_ASSERT(std::is_same
<decltype(f3
), boost::future
<boost::future
<void> > >::value
);
123 std::cout
<< __FILE__
<< "[" << __LINE__
<< "]" << std::endl
;
124 for (int i
=0; i
< number_of_tests
; i
++)
126 boost::make_ready_future().then(
127 TestCallback()).unwrap().then(TestCallback()).get();
129 std::cout
<< __FILE__
<< "[" << __LINE__
<< "]" << std::endl
;
130 for (int i
=0; i
< number_of_tests
; i
++)
132 boost::future
<void> f
= boost::async(p1
);
134 TestCallback()).unwrap().then(TestCallback()).get();
136 std::cout
<< __FILE__
<< "[" << __LINE__
<< "]" << std::endl
;
137 for (int i
=0; i
< number_of_tests
; i
++)
139 auto f1
= boost::make_ready_future().then(TestCallback());
140 BOOST_STATIC_ASSERT(std::is_same
<decltype(f1
), boost::future
<boost::future
<void> > >::value
);
141 auto f3
= f1
.then(TestCallback());
142 BOOST_STATIC_ASSERT(std::is_same
<decltype(f3
), boost::future
<boost::future
<void> > >::value
);
145 std::cout
<< __FILE__
<< "[" << __LINE__
<< "]" << std::endl
;
146 for (int i
=0; i
< number_of_tests
; i
++)
148 boost::basic_thread_pool executor
;
149 auto f1
= boost::make_ready_future().then(executor
, TestCallback());
150 BOOST_STATIC_ASSERT(std::is_same
<decltype(f1
), boost::future
<boost::future
<void> > >::value
);
151 auto f3
= f1
.then(executor
, TestCallback());
152 BOOST_STATIC_ASSERT(std::is_same
<decltype(f3
), boost::future
<boost::future
<void> > >::value
);
156 std::cout
<< __FILE__
<< "[" << __LINE__
<< "]" << std::endl
;
158 for (int i
=0; i
< number_of_tests
; i
++)
160 boost::basic_thread_pool
executor(2);
162 auto f1
= boost::make_ready_future().then(executor
, TestCallback());
163 BOOST_STATIC_ASSERT(std::is_same
<decltype(f1
), boost::future
<boost::future
<void> > >::value
);
164 std::cout
<< __FILE__
<< "[" << __LINE__
<< "] " << int(f1
.valid()) << std::endl
;
165 auto f2
= f1
.unwrap();
166 std::cout
<< __FILE__
<< "[" << __LINE__
<< "] " << int(f2
.valid()) << std::endl
;
168 BOOST_STATIC_ASSERT(std::is_same
<decltype(f2
), boost::future
<void> >::value
);
169 auto f3
= f2
.then(executor
, TestCallback());
170 BOOST_STATIC_ASSERT(std::is_same
<decltype(f3
), boost::future
<boost::future
<void> > >::value
);
174 std::cout
<< __FILE__
<< "[" << __LINE__
<< "]" << std::endl
;
175 for (int i
=0; i
< number_of_tests
; i
++)
177 boost::basic_thread_pool executor
;
179 auto f1
= boost::make_ready_future().then(executor
, TestCallback());
180 BOOST_STATIC_ASSERT(std::is_same
<decltype(f1
), boost::future
<boost::future
<void> > >::value
);
181 auto f2
= f1
.unwrap();
182 BOOST_STATIC_ASSERT(std::is_same
<decltype(f2
), boost::future
<void> >::value
);
183 auto f3
= f2
.then(executor
, TestCallback());
184 BOOST_STATIC_ASSERT(std::is_same
<decltype(f3
), boost::future
<boost::future
<void> > >::value
);
187 std::cout
<< __FILE__
<< "[" << __LINE__
<< "]" << std::endl
;