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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
|
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// Copyright (C) 2014 Vicente J. Botet Escriba
//
// 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)
// <boost/thread/future.hpp>
// template <class T, class Ts>
// future<tuple<T>> when_all(T&&);
#include <boost/config.hpp>
#if ! defined BOOST_NO_CXX11_DECLTYPE
#define BOOST_RESULT_OF_USE_DECLTYPE
#endif
#define BOOST_THREAD_VERSION 4
#include <boost/thread/future.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <stdexcept>
#ifdef BOOST_MSVC
#pragma warning(disable: 4127) // conditional expression is constant
#endif
int p1()
{
return 123;
}
int thr()
{
throw std::logic_error("123");
}
int main()
{
#if defined BOOST_THREAD_PROVIDES_FUTURE_WHEN_ALL_WHEN_ANY
if (0) // todo not yet implemented
{ // invalid future copy-constructible
boost::future<int> f1;
BOOST_TEST(! f1.valid());
boost::future<boost::csbl::tuple<boost::future<int> > > all = boost::when_all(boost::move(f1));
BOOST_TEST(! f1.valid());
BOOST_TEST(all.valid());
boost::csbl::tuple<boost::future<int> > res = all.get();
BOOST_TEST(boost::csbl::get<0>(res).valid());
BOOST_TEST(boost::csbl::get<0>(res).is_ready());
// has exception
//BOOST_TEST(boost::csbl::get<0>(res).get() == 123);
}
{ // is_ready future copy-constructible
boost::future<int> f1 = boost::make_ready_future(123);
BOOST_TEST(f1.valid());
BOOST_TEST(f1.is_ready());
boost::future<boost::csbl::tuple<boost::future<int> > > all = boost::when_all(boost::move(f1));
BOOST_TEST(! f1.valid());
BOOST_TEST(all.valid());
if (0) // todo FAILS not yet implemented
BOOST_TEST(all.is_ready());
boost::csbl::tuple<boost::future<int> > res = all.get();
BOOST_TEST(boost::csbl::get<0>(res).valid());
BOOST_TEST(boost::csbl::get<0>(res).is_ready());
BOOST_TEST(boost::csbl::get<0>(res).get() == 123);
}
{ // is_ready shared_future copy-constructible
boost::shared_future<int> f1 = boost::make_ready_future(123).share();
BOOST_TEST(f1.valid());
BOOST_TEST(f1.is_ready());
boost::future<boost::csbl::tuple<boost::shared_future<int> > > all = boost::when_all(f1);
BOOST_TEST(f1.valid());
BOOST_TEST(all.valid());
if (0) // todo FAILS not yet implemented
BOOST_TEST(all.is_ready());
boost::csbl::tuple<boost::shared_future<int> > res = all.get();
BOOST_TEST(boost::csbl::get<0>(res).valid());
BOOST_TEST(boost::csbl::get<0>(res).is_ready());
BOOST_TEST(boost::csbl::get<0>(res).get() == 123);
}
{ // packaged_task future copy-constructible
boost::packaged_task<int()> pt1(&p1);
boost::future<int> f1 = pt1.get_future();
BOOST_TEST(f1.valid());
boost::future<boost::csbl::tuple<boost::future<int> > > all = boost::when_all(boost::move(f1));
BOOST_TEST(! f1.valid());
BOOST_TEST(all.valid());
pt1();
boost::csbl::tuple<boost::future<int> > res = all.get();
BOOST_TEST(boost::csbl::get<0>(res).valid());
BOOST_TEST(boost::csbl::get<0>(res).is_ready());
BOOST_TEST(boost::csbl::get<0>(res).get() == 123);
}
{ // packaged_task shared_future copy-constructible
boost::packaged_task<int()> pt1(&p1);
boost::shared_future<int> f1 = pt1.get_future().share();
BOOST_TEST(f1.valid());
boost::future<boost::csbl::tuple<boost::shared_future<int> > > all = boost::when_all(f1);
BOOST_TEST(f1.valid());
BOOST_TEST(all.valid());
pt1();
boost::csbl::tuple<boost::shared_future<int> > res = all.get();
BOOST_TEST(boost::csbl::get<0>(res).valid());
BOOST_TEST(boost::csbl::get<0>(res).is_ready());
BOOST_TEST(boost::csbl::get<0>(res).get() == 123);
}
{ // packaged_task future copy-constructible
boost::packaged_task<int()> pt1(&thr);
boost::future<int> f1 = pt1.get_future();
BOOST_TEST(f1.valid());
boost::future<boost::csbl::tuple<boost::future<int> > > all = boost::when_all(boost::move(f1));
BOOST_TEST(! f1.valid());
BOOST_TEST(all.valid());
pt1();
boost::csbl::tuple<boost::future<int> > res = all.get();
BOOST_TEST(boost::csbl::get<0>(res).valid());
BOOST_TEST(boost::csbl::get<0>(res).is_ready());
try {
boost::csbl::get<0>(res).get();
BOOST_TEST(false);
} catch (std::logic_error& ex) {
BOOST_TEST(ex.what() == std::string("123"));
} catch (...) {
BOOST_TEST(false);
}
}
{ // async future copy-constructible
boost::future<int> f1 = boost::async(boost::launch::async, &p1);
BOOST_TEST(f1.valid());
boost::future<boost::csbl::tuple<boost::future<int> > > all = boost::when_all(boost::move(f1));
BOOST_TEST(! f1.valid());
BOOST_TEST(all.valid());
boost::csbl::tuple<boost::future<int> > res = all.get();
BOOST_TEST(boost::csbl::get<0>(res).valid());
BOOST_TEST(boost::csbl::get<0>(res).is_ready());
BOOST_TEST(boost::csbl::get<0>(res).get() == 123);
}
{ // async shared_future copy-constructible
boost::shared_future<int> f1 = boost::async(boost::launch::async, &p1).share();
BOOST_TEST(f1.valid());
boost::future<boost::csbl::tuple<boost::shared_future<int> > > all = boost::when_all(f1);
BOOST_TEST(f1.valid());
BOOST_TEST(all.valid());
boost::csbl::tuple<boost::shared_future<int> > res = all.get();
BOOST_TEST(boost::csbl::get<0>(res).valid());
BOOST_TEST(boost::csbl::get<0>(res).is_ready());
BOOST_TEST(boost::csbl::get<0>(res).get() == 123);
}
#if defined BOOST_THREAD_PROVIDES_VARIADIC_THREAD
// fixme darwin-4.8.0_11 terminate called without an active exception
{ // deferred future copy-constructible
boost::future<int> f1 = boost::async(boost::launch::deferred, &p1);
boost::future<boost::csbl::tuple<boost::future<int> > > all = boost::when_all(boost::move(f1));
BOOST_TEST(! f1.valid());
BOOST_TEST(all.valid());
boost::csbl::tuple<boost::future<int> > res = all.get();
BOOST_TEST(boost::csbl::get<0>(res).valid());
BOOST_TEST(boost::csbl::get<0>(res).is_ready());
BOOST_TEST(boost::csbl::get<0>(res).get() == 123);
}
// fixme darwin-4.8.0_11 terminate called without an active exception
{ // deferred shared_future copy-constructible
boost::shared_future<int> f1 = boost::async(boost::launch::deferred, &p1).share();
boost::future<boost::csbl::tuple<boost::shared_future<int> > > all = boost::when_all(f1);
BOOST_TEST(f1.valid());
BOOST_TEST(all.valid());
boost::csbl::tuple<boost::shared_future<int> > res = all.get();
BOOST_TEST(boost::csbl::get<0>(res).valid());
BOOST_TEST(boost::csbl::get<0>(res).is_ready());
BOOST_TEST(boost::csbl::get<0>(res).get() == 123);
}
#endif
#endif
return boost::report_errors();
}
|