1 | // (C) Copyright 2008-10 Anthony Williams |
2 | // (C) Copyright 2011-2015 Vicente J. Botet Escriba |
3 | // |
4 | // Distributed under the Boost Software License, Version 1.0. (See |
5 | // accompanying file LICENSE_1_0.txt or copy at |
6 | // http://www.boost.org/LICENSE_1_0.txt) |
7 | |
8 | #ifndef BOOST_THREAD_FUTURES_WAIT_FOR_ALL_HPP |
9 | #define BOOST_THREAD_FUTURES_WAIT_FOR_ALL_HPP |
10 | |
11 | #include <boost/thread/detail/config.hpp> |
12 | #include <boost/thread/futures/is_future_type.hpp> |
13 | |
14 | #include <boost/core/enable_if.hpp> |
15 | |
16 | namespace boost |
17 | { |
18 | template<typename Iterator> |
19 | typename boost::disable_if<is_future_type<Iterator>,void>::type wait_for_all(Iterator begin,Iterator end) |
20 | { |
21 | for(Iterator current=begin;current!=end;++current) |
22 | { |
23 | current->wait(); |
24 | } |
25 | } |
26 | |
27 | #ifdef BOOST_NO_CXX11_VARIADIC_TEMPLATES |
28 | template<typename F1,typename F2> |
29 | typename boost::enable_if<is_future_type<F1>,void>::type wait_for_all(F1& f1,F2& f2) |
30 | { |
31 | f1.wait(); |
32 | f2.wait(); |
33 | } |
34 | |
35 | template<typename F1,typename F2,typename F3> |
36 | void wait_for_all(F1& f1,F2& f2,F3& f3) |
37 | { |
38 | f1.wait(); |
39 | f2.wait(); |
40 | f3.wait(); |
41 | } |
42 | |
43 | template<typename F1,typename F2,typename F3,typename F4> |
44 | void wait_for_all(F1& f1,F2& f2,F3& f3,F4& f4) |
45 | { |
46 | f1.wait(); |
47 | f2.wait(); |
48 | f3.wait(); |
49 | f4.wait(); |
50 | } |
51 | |
52 | template<typename F1,typename F2,typename F3,typename F4,typename F5> |
53 | void wait_for_all(F1& f1,F2& f2,F3& f3,F4& f4,F5& f5) |
54 | { |
55 | f1.wait(); |
56 | f2.wait(); |
57 | f3.wait(); |
58 | f4.wait(); |
59 | f5.wait(); |
60 | } |
61 | #else |
62 | template<typename F1, typename... Fs> |
63 | typename boost::enable_if<is_future_type<F1>,void>::type wait_for_all(F1& f1, Fs&... fs) |
64 | { |
65 | bool dummy[] = { (f1.wait(), true), (fs.wait(), true)... }; |
66 | |
67 | // prevent unused parameter warning |
68 | (void) dummy; |
69 | } |
70 | #endif // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)} |
71 | |
72 | } |
73 | |
74 | #endif // header |
75 | |