
----- Original Message ----- From: "Hartmut Kaiser" <hartmut.kaiser@gmail.com> To: <boost@lists.boost.org> Sent: Friday, May 30, 2008 9:10 PM Subject: Re: [boost] Updated version of futures library
I've updated my futures library to include wait_for_any() and wait_for_all().
The provided overloads allow either waiting on up to five futures known at compile time:
unique_future<int> f1; shared_future<std::string> f2; unique_future<double> f3; unsigned const ready_index=wait_for_any(future1,future2,future3);
or on a container of futures:
std::vector<jss::shared_future<int> > futures; std::vector<jss::shared_future<int> >::iterator const future= jss::wait_for_any(futures.begin(),futures.end());
In the first instance, they can be of distinct types, but in the latter, all the futures in the container must be of the same type.
The documentation is available at http://www.justsoftwaresolutions.co.uk/files/futures_documentation.html and the files and tests are available at http://www.justsoftwaresolutions.co.uk/files/n2561_futures_revised_2008 0530.zip
This reminds me of a discussion we had some time ago, namely overloading operator&&() for futures allowing to achieve the same thing: waiting for all of the futures:
future<int> f1; future<double> f2; future<fusion::vector<int, double> > f3 (f1 && f2);
fusion::vector<int, double> result = f3.get(); // waits for f1 and f2
Similarly, overloading operator|| would allow to wait for the first future to finish only:
future<int> f1; future<double> f2; future<variant<int, double> > f3 (f1 || f2);
variant<int, double> result = f3.get(); // waits for first, f1 or f2
Hello, I think that the problem with the operator is not its implementation, but its definition. Your proposal seams natural for && and for || when the types are different. But when we have comon types things start to be more complicated for operator ||. When all are differents we can know via the type which future has finished the first. This information is lost otherwise. Which type will have (f1 || f2) if future<string> f1; future<string> f2; If we don't mind which future has finished, future<string> should be good (does variant<string, string> work in this case?). If we mind a future<pair<unsigned, string> > . The first component give the index, athe second the result. The problem is that this do not scale to more that 2 futures. Which type will have (f1 || f2|| f3) if future<string> f1; future<string> f2; future<int> f3; future<variant<string, int> > f3 (f1 || f2 || f3); or future<pair<unsigned, <variant<string, int> > > f3 (f1 || f2 || f3); Vicente