]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/thread/test/sync/futures/when_any/one_pass.cpp
1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Copyright (C) 2014 Vicente J. Botet Escriba
12 // Distributed under the Boost Software License, Version 1.0. (See accompanying
13 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
15 // <boost/thread/future.hpp>
17 // future<tuple<T>> when_any(T&&);
19 #include <boost/config.hpp>
21 #if ! defined BOOST_NO_CXX11_DECLTYPE
22 #define BOOST_RESULT_OF_USE_DECLTYPE
26 #define BOOST_THREAD_VERSION 4
28 #include <boost/thread/future.hpp>
29 #include <boost/detail/lightweight_test.hpp>
32 #pragma warning(disable: 4127) // conditional expression is constant
42 #if defined BOOST_THREAD_PROVIDES_FUTURE_WHEN_ALL_WHEN_ANY
43 if (0) // todo not yet implemented
44 { // invalid future copy-constructible
45 boost::future
<int> f1
;
46 BOOST_TEST(! f1
.valid());
47 boost::future
<boost::csbl::tuple
<boost::future
<int> > > all
= boost::when_any(boost::move(f1
));
48 BOOST_TEST(! f1
.valid());
49 BOOST_TEST(all
.valid());
50 boost::csbl::tuple
<boost::future
<int> > res
= all
.get();
51 BOOST_TEST(boost::csbl::get
<0>(res
).valid());
52 BOOST_TEST(boost::csbl::get
<0>(res
).is_ready());
54 //BOOST_TEST(boost::csbl::get<0>(res).get() == 123);
56 { // is_ready future copy-constructible
57 boost::future
<int> f1
= boost::make_ready_future(123);
58 BOOST_TEST(f1
.valid());
59 BOOST_TEST(f1
.is_ready());
60 boost::future
<boost::csbl::tuple
<boost::future
<int> > > all
= boost::when_any(boost::move(f1
));
61 BOOST_TEST(! f1
.valid());
62 BOOST_TEST(all
.valid());
63 if (0) // todo FAILS not yet implemented
64 BOOST_TEST(all
.is_ready());
65 boost::csbl::tuple
<boost::future
<int> > res
= all
.get();
66 BOOST_TEST(boost::csbl::get
<0>(res
).valid());
67 BOOST_TEST(boost::csbl::get
<0>(res
).is_ready());
68 BOOST_TEST(boost::csbl::get
<0>(res
).get() == 123);
70 { // is_ready shared_future copy-constructible
71 boost::shared_future
<int> f1
= boost::make_ready_future(123).share();
72 BOOST_TEST(f1
.valid());
73 BOOST_TEST(f1
.is_ready());
74 boost::future
<boost::csbl::tuple
<boost::shared_future
<int> > > all
= boost::when_any(f1
);
75 BOOST_TEST(f1
.valid());
76 BOOST_TEST(all
.valid());
77 if (0) // todo FAILS not yet implemented
78 BOOST_TEST(all
.is_ready());
79 boost::csbl::tuple
<boost::shared_future
<int> > res
= all
.get();
80 BOOST_TEST(boost::csbl::get
<0>(res
).valid());
81 BOOST_TEST(boost::csbl::get
<0>(res
).is_ready());
82 BOOST_TEST(boost::csbl::get
<0>(res
).get() == 123);
84 { // packaged_task future copy-constructible
85 boost::packaged_task
<int()> pt1(&p1
);
86 boost::future
<int> f1
= pt1
.get_future();
87 BOOST_TEST(f1
.valid());
88 boost::future
<boost::csbl::tuple
<boost::future
<int> > > all
= boost::when_any(boost::move(f1
));
89 BOOST_TEST(! f1
.valid());
90 BOOST_TEST(all
.valid());
92 boost::csbl::tuple
<boost::future
<int> > res
= all
.get();
93 BOOST_TEST(boost::csbl::get
<0>(res
).valid());
94 BOOST_TEST(boost::csbl::get
<0>(res
).is_ready());
95 BOOST_TEST(boost::csbl::get
<0>(res
).get() == 123);
97 { // packaged_task shared_future copy-constructible
98 boost::packaged_task
<int()> pt1(&p1
);
99 boost::shared_future
<int> f1
= pt1
.get_future().share();
100 BOOST_TEST(f1
.valid());
101 boost::future
<boost::csbl::tuple
<boost::shared_future
<int> > > all
= boost::when_any(f1
);
102 BOOST_TEST(f1
.valid());
103 BOOST_TEST(all
.valid());
105 boost::csbl::tuple
<boost::shared_future
<int> > res
= all
.get();
106 BOOST_TEST(boost::csbl::get
<0>(res
).valid());
107 BOOST_TEST(boost::csbl::get
<0>(res
).is_ready());
108 BOOST_TEST(boost::csbl::get
<0>(res
).get() == 123);
110 { // async future copy-constructible
111 boost::future
<int> f1
= boost::async(boost::launch::async
, &p1
);
112 BOOST_TEST(f1
.valid());
113 boost::future
<boost::csbl::tuple
<boost::future
<int> > > all
= boost::when_any(boost::move(f1
));
114 BOOST_TEST(! f1
.valid());
115 BOOST_TEST(all
.valid());
116 boost::csbl::tuple
<boost::future
<int> > res
= all
.get();
117 BOOST_TEST(boost::csbl::get
<0>(res
).valid());
118 BOOST_TEST(boost::csbl::get
<0>(res
).is_ready());
119 BOOST_TEST(boost::csbl::get
<0>(res
).get() == 123);
121 { // async shared_future copy-constructible
122 boost::shared_future
<int> f1
= boost::async(boost::launch::async
, &p1
).share();
123 BOOST_TEST(f1
.valid());
124 boost::future
<boost::csbl::tuple
<boost::shared_future
<int> > > all
= boost::when_any(f1
);
125 BOOST_TEST(f1
.valid());
126 BOOST_TEST(all
.valid());
127 boost::csbl::tuple
<boost::shared_future
<int> > res
= all
.get();
128 BOOST_TEST(boost::csbl::get
<0>(res
).valid());
129 BOOST_TEST(boost::csbl::get
<0>(res
).is_ready());
130 BOOST_TEST(boost::csbl::get
<0>(res
).get() == 123);
132 #if defined BOOST_THREAD_PROVIDES_VARIADIC_THREAD
133 // fixme darwin-4.8.0_11 terminate called without an active exception
134 { // deferred future copy-constructible
135 boost::future
<int> f1
= boost::async(boost::launch::deferred
, &p1
);
136 boost::future
<boost::csbl::tuple
<boost::future
<int> > > all
= boost::when_any(boost::move(f1
));
137 BOOST_TEST(! f1
.valid());
138 BOOST_TEST(all
.valid());
139 boost::csbl::tuple
<boost::future
<int> > res
= all
.get();
140 BOOST_TEST(boost::csbl::get
<0>(res
).valid());
141 BOOST_TEST(boost::csbl::get
<0>(res
).is_ready());
142 BOOST_TEST(boost::csbl::get
<0>(res
).get() == 123);
144 // fixme darwin-4.8.0_11 terminate called without an active exception
145 { // deferred shared_future copy-constructible
146 boost::shared_future
<int> f1
= boost::async(boost::launch::deferred
, &p1
).share();
147 boost::future
<boost::csbl::tuple
<boost::shared_future
<int> > > all
= boost::when_any(f1
);
148 BOOST_TEST(f1
.valid());
149 BOOST_TEST(all
.valid());
150 boost::csbl::tuple
<boost::shared_future
<int> > res
= all
.get();
151 BOOST_TEST(boost::csbl::get
<0>(res
).valid());
152 BOOST_TEST(boost::csbl::get
<0>(res
).is_ready());
153 BOOST_TEST(boost::csbl::get
<0>(res
).get() == 123);
157 return boost::report_errors();