]>
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>
38 #if defined BOOST_THREAD_PROVIDES_FUTURE_WHEN_ALL_WHEN_ANY
39 if (0) // todo not yet implemented
40 { // invalid future copy-constructible
41 boost::future
<int> f1
;
42 BOOST_TEST(! f1
.valid());
43 boost::future
<boost::csbl::tuple
<boost::future
<int> > > all
= boost::when_any(boost::move(f1
));
44 BOOST_TEST(! f1
.valid());
45 BOOST_TEST(all
.valid());
46 boost::csbl::tuple
<boost::future
<int> > res
= all
.get();
47 BOOST_TEST(boost::csbl::get
<0>(res
).valid());
48 BOOST_TEST(boost::csbl::get
<0>(res
).is_ready());
50 //BOOST_TEST(boost::csbl::get<0>(res).get() == 123);
52 { // is_ready future copy-constructible
53 boost::future
<int> f1
= boost::make_ready_future(123);
54 BOOST_TEST(f1
.valid());
55 BOOST_TEST(f1
.is_ready());
56 boost::future
<boost::csbl::tuple
<boost::future
<int> > > all
= boost::when_any(boost::move(f1
));
57 BOOST_TEST(! f1
.valid());
58 BOOST_TEST(all
.valid());
59 if (0) // todo FAILS not yet implemented
60 BOOST_TEST(all
.is_ready());
61 boost::csbl::tuple
<boost::future
<int> > res
= all
.get();
62 BOOST_TEST(boost::csbl::get
<0>(res
).valid());
63 BOOST_TEST(boost::csbl::get
<0>(res
).is_ready());
64 BOOST_TEST(boost::csbl::get
<0>(res
).get() == 123);
66 { // is_ready shared_future copy-constructible
67 boost::shared_future
<int> f1
= boost::make_ready_future(123).share();
68 BOOST_TEST(f1
.valid());
69 BOOST_TEST(f1
.is_ready());
70 boost::future
<boost::csbl::tuple
<boost::shared_future
<int> > > all
= boost::when_any(f1
);
71 BOOST_TEST(f1
.valid());
72 BOOST_TEST(all
.valid());
73 if (0) // todo FAILS not yet implemented
74 BOOST_TEST(all
.is_ready());
75 boost::csbl::tuple
<boost::shared_future
<int> > res
= all
.get();
76 BOOST_TEST(boost::csbl::get
<0>(res
).valid());
77 BOOST_TEST(boost::csbl::get
<0>(res
).is_ready());
78 BOOST_TEST(boost::csbl::get
<0>(res
).get() == 123);
80 { // packaged_task future copy-constructible
81 boost::packaged_task
<int()> pt1(&p1
);
82 boost::future
<int> f1
= pt1
.get_future();
83 BOOST_TEST(f1
.valid());
84 boost::future
<boost::csbl::tuple
<boost::future
<int> > > all
= boost::when_any(boost::move(f1
));
85 BOOST_TEST(! f1
.valid());
86 BOOST_TEST(all
.valid());
88 boost::csbl::tuple
<boost::future
<int> > res
= all
.get();
89 BOOST_TEST(boost::csbl::get
<0>(res
).valid());
90 BOOST_TEST(boost::csbl::get
<0>(res
).is_ready());
91 BOOST_TEST(boost::csbl::get
<0>(res
).get() == 123);
93 { // packaged_task shared_future copy-constructible
94 boost::packaged_task
<int()> pt1(&p1
);
95 boost::shared_future
<int> f1
= pt1
.get_future().share();
96 BOOST_TEST(f1
.valid());
97 boost::future
<boost::csbl::tuple
<boost::shared_future
<int> > > all
= boost::when_any(f1
);
98 BOOST_TEST(f1
.valid());
99 BOOST_TEST(all
.valid());
101 boost::csbl::tuple
<boost::shared_future
<int> > res
= all
.get();
102 BOOST_TEST(boost::csbl::get
<0>(res
).valid());
103 BOOST_TEST(boost::csbl::get
<0>(res
).is_ready());
104 BOOST_TEST(boost::csbl::get
<0>(res
).get() == 123);
106 { // async future copy-constructible
107 boost::future
<int> f1
= boost::async(boost::launch::async
, &p1
);
108 BOOST_TEST(f1
.valid());
109 boost::future
<boost::csbl::tuple
<boost::future
<int> > > all
= boost::when_any(boost::move(f1
));
110 BOOST_TEST(! f1
.valid());
111 BOOST_TEST(all
.valid());
112 boost::csbl::tuple
<boost::future
<int> > res
= all
.get();
113 BOOST_TEST(boost::csbl::get
<0>(res
).valid());
114 BOOST_TEST(boost::csbl::get
<0>(res
).is_ready());
115 BOOST_TEST(boost::csbl::get
<0>(res
).get() == 123);
117 { // async shared_future copy-constructible
118 boost::shared_future
<int> f1
= boost::async(boost::launch::async
, &p1
).share();
119 BOOST_TEST(f1
.valid());
120 boost::future
<boost::csbl::tuple
<boost::shared_future
<int> > > all
= boost::when_any(f1
);
121 BOOST_TEST(f1
.valid());
122 BOOST_TEST(all
.valid());
123 boost::csbl::tuple
<boost::shared_future
<int> > res
= all
.get();
124 BOOST_TEST(boost::csbl::get
<0>(res
).valid());
125 BOOST_TEST(boost::csbl::get
<0>(res
).is_ready());
126 BOOST_TEST(boost::csbl::get
<0>(res
).get() == 123);
128 #if defined BOOST_THREAD_PROVIDES_VARIADIC_THREAD
129 // fixme darwin-4.8.0_11 terminate called without an active exception
130 { // deferred future copy-constructible
131 boost::future
<int> f1
= boost::async(boost::launch::deferred
, &p1
);
132 boost::future
<boost::csbl::tuple
<boost::future
<int> > > all
= boost::when_any(boost::move(f1
));
133 BOOST_TEST(! f1
.valid());
134 BOOST_TEST(all
.valid());
135 boost::csbl::tuple
<boost::future
<int> > res
= all
.get();
136 BOOST_TEST(boost::csbl::get
<0>(res
).valid());
137 BOOST_TEST(boost::csbl::get
<0>(res
).is_ready());
138 BOOST_TEST(boost::csbl::get
<0>(res
).get() == 123);
140 // fixme darwin-4.8.0_11 terminate called without an active exception
141 { // deferred shared_future copy-constructible
142 boost::shared_future
<int> f1
= boost::async(boost::launch::deferred
, &p1
).share();
143 boost::future
<boost::csbl::tuple
<boost::shared_future
<int> > > all
= boost::when_any(f1
);
144 BOOST_TEST(f1
.valid());
145 BOOST_TEST(all
.valid());
146 boost::csbl::tuple
<boost::shared_future
<int> > res
= all
.get();
147 BOOST_TEST(boost::csbl::get
<0>(res
).valid());
148 BOOST_TEST(boost::csbl::get
<0>(res
).is_ready());
149 BOOST_TEST(boost::csbl::get
<0>(res
).get() == 123);
153 return boost::report_errors();