1 | // Copyright (C) 2014 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 | |
19 | struct TestCallback |
20 | { |
21 | typedef boost::future<void> result_type; |
22 | |
23 | result_type operator()(boost::future<void> future) const |
24 | { |
25 | assert(future.is_ready()); |
26 | future.get(); |
27 | return boost::make_ready_future(); |
28 | } |
29 | |
30 | result_type operator()(boost::future<boost::future<void> > future) const |
31 | { |
32 | assert(future.is_ready()); |
33 | future.get(); |
34 | return boost::make_ready_future(); |
35 | } |
36 | }; |
37 | |
38 | int main() |
39 | { |
40 | #if ! defined BOOST_NO_CXX11_DECLTYPE && ! defined BOOST_NO_CXX11_AUTO_DECLARATIONS |
41 | { |
42 | boost::promise<void> test_promise; |
43 | boost::future<void> test_future(test_promise.get_future()); |
44 | auto f1 = test_future.then(func: TestCallback()); |
45 | BOOST_STATIC_ASSERT(std::is_same<decltype(f1), boost::future<boost::future<void> > >::value); |
46 | auto f2 = f1.then(func: TestCallback()); |
47 | BOOST_STATIC_ASSERT(std::is_same<decltype(f2), boost::future<boost::future<void> > >::value); |
48 | } |
49 | { |
50 | boost::basic_thread_pool executor; |
51 | boost::promise<void> test_promise; |
52 | boost::future<void> test_future(test_promise.get_future()); |
53 | auto f1 = test_future.then(ex&: executor, func: TestCallback()); |
54 | BOOST_STATIC_ASSERT(std::is_same<decltype(f1), boost::future<boost::future<void> > >::value); |
55 | auto f2 = f1.then(ex&: executor, func: TestCallback()); |
56 | BOOST_STATIC_ASSERT(std::is_same<decltype(f2), boost::future<boost::future<void> > >::value); |
57 | |
58 | } |
59 | #endif |
60 | return 0; |
61 | } |
62 |