blob: d8fd8e3e812aa63551463a9bf3a2b363be86584e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
// Copyright (C) 2014 Vicente Botet
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#define BOOST_THREAD_PROVIDES_FUTURE
#define BOOST_THREAD_PROVIDES_FUTURE_CONTINUATION
#include <boost/config.hpp>
#if ! defined BOOST_NO_CXX11_DECLTYPE
#define BOOST_RESULT_OF_USE_DECLTYPE
#endif
#include <boost/thread/future.hpp>
int main()
{
#if ! defined BOOST_NO_CXX11_LAMBDAS && ! (defined BOOST_MSVC && _MSC_VER < 1700)
boost::promise<int> prom;
boost::future<int> futr = prom.get_future();
int callCount = 0;
boost::future<void> futr2 = futr.then(boost::launch::deferred,
[&] (boost::future<int> f) {
callCount++;
assert(f.valid());
assert(f.is_ready());
assert(17 == f.get());
});
assert(futr2.valid());
assert(!futr2.is_ready());
assert(0 == callCount);
prom.set_value(17);
assert(0 == callCount);
futr2.get();
assert(1 == callCount);
#endif
return 0;
}
|