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>
16 #include <boost/thread/executors/basic_thread_pool.hpp>
20 typedef boost::future
<void> result_type
;
22 result_type
operator()(boost::future
<void> future
) const
24 std::cout
<< __FILE__
<< "[" << __LINE__
<< "]" << std::endl
;
25 assert(future
.is_ready());
26 std::cout
<< __FILE__
<< "[" << __LINE__
<< "]" << std::endl
;
28 std::cout
<< __FILE__
<< "[" << __LINE__
<< "]" << std::endl
;
29 return boost::make_ready_future();
32 result_type
operator()(boost::future
<boost::future
<void> > future
) const
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();
41 return boost::make_ready_future();
43 result_type
operator()(boost::shared_future
<void> future
) const
45 std::cout
<< __FILE__
<< "[" << __LINE__
<< "]" << std::endl
;
46 assert(future
.is_ready());
47 std::cout
<< __FILE__
<< "[" << __LINE__
<< "]" << std::endl
;
49 std::cout
<< __FILE__
<< "[" << __LINE__
<< "]" << std::endl
;
50 return boost::make_ready_future();
53 result_type
operator()(boost::shared_future
<boost::future
<void> > future
) const
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();
62 return boost::make_ready_future();
72 const int number_of_tests
= 2;
73 (void)(number_of_tests
);
75 #if ! defined BOOST_NO_CXX11_DECLTYPE && ! defined BOOST_NO_CXX11_AUTO_DECLARATIONS
76 std::cout
<< __FILE__
<< "[" << __LINE__
<< "]" << std::endl
;
78 auto f1
= boost::make_ready_future().then(TestCallback());
79 BOOST_STATIC_ASSERT(std::is_same
<decltype(f1
), boost::future
<boost::future
<void> > >::value
);
82 std::cout
<< __FILE__
<< "[" << __LINE__
<< "]" << std::endl
;
83 for (int i
=0; i
< number_of_tests
; i
++)
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
;
94 std::cout
<< __FILE__
<< "[" << __LINE__
<< "]" << std::endl
;
96 std::cout
<< __FILE__
<< "[" << __LINE__
<< "]" << std::endl
;
97 for (int i
=0; i
< number_of_tests
; i
++)
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();
103 std::cout
<< __FILE__
<< "[" << __LINE__
<< "]" << std::endl
;
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
);
111 std::cout
<< __FILE__
<< "[" << __LINE__
<< "]" << std::endl
;
112 for (int i
=0; i
< number_of_tests
; i
++)
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
);
122 std::cout
<< __FILE__
<< "[" << __LINE__
<< "]" << std::endl
;
123 for (int i
=0; i
< number_of_tests
; i
++)
125 boost::make_ready_future().then(
126 TestCallback()).unwrap().then(TestCallback()).get();
128 std::cout
<< __FILE__
<< "[" << __LINE__
<< "]" << std::endl
;
129 for (int i
=0; i
< number_of_tests
; i
++)
131 boost::future
<void> f
= boost::async(p1
);
133 TestCallback()).unwrap().then(TestCallback()).get();
135 std::cout
<< __FILE__
<< "[" << __LINE__
<< "]" << std::endl
;
136 for (int i
=0; i
< number_of_tests
; i
++)
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
);
144 std::cout
<< __FILE__
<< "[" << __LINE__
<< "]" << std::endl
;
145 for (int i
=0; i
< number_of_tests
; i
++)
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
);
155 std::cout
<< __FILE__
<< "[" << __LINE__
<< "]" << std::endl
;
157 for (int i
=0; i
< number_of_tests
; i
++)
159 boost::basic_thread_pool
executor(2);
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
;
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
);
173 std::cout
<< __FILE__
<< "[" << __LINE__
<< "]" << std::endl
;
174 for (int i
=0; i
< number_of_tests
; i
++)
176 boost::basic_thread_pool executor
;
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
);
186 std::cout
<< __FILE__
<< "[" << __LINE__
<< "]" << std::endl
;