wait_for_all.hpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. #ifndef BOOST_THREAD_FUTURES_WAIT_FOR_ALL_HPP
  8. #define BOOST_THREAD_FUTURES_WAIT_FOR_ALL_HPP
  9. #include <boost/thread/detail/config.hpp>
  10. #include <boost/thread/futures/is_future_type.hpp>
  11. #include <boost/core/enable_if.hpp>
  12. namespace boost
  13. {
  14. template<typename Iterator>
  15. typename boost::disable_if<is_future_type<Iterator>,void>::type wait_for_all(Iterator begin,Iterator end)
  16. {
  17. for(Iterator current=begin;current!=end;++current)
  18. {
  19. current->wait();
  20. }
  21. }
  22. #ifdef BOOST_NO_CXX11_VARIADIC_TEMPLATES
  23. template<typename F1,typename F2>
  24. typename boost::enable_if<is_future_type<F1>,void>::type wait_for_all(F1& f1,F2& f2)
  25. {
  26. f1.wait();
  27. f2.wait();
  28. }
  29. template<typename F1,typename F2,typename F3>
  30. void wait_for_all(F1& f1,F2& f2,F3& f3)
  31. {
  32. f1.wait();
  33. f2.wait();
  34. f3.wait();
  35. }
  36. template<typename F1,typename F2,typename F3,typename F4>
  37. void wait_for_all(F1& f1,F2& f2,F3& f3,F4& f4)
  38. {
  39. f1.wait();
  40. f2.wait();
  41. f3.wait();
  42. f4.wait();
  43. }
  44. template<typename F1,typename F2,typename F3,typename F4,typename F5>
  45. void wait_for_all(F1& f1,F2& f2,F3& f3,F4& f4,F5& f5)
  46. {
  47. f1.wait();
  48. f2.wait();
  49. f3.wait();
  50. f4.wait();
  51. f5.wait();
  52. }
  53. #else
  54. template<typename F1, typename... Fs>
  55. typename boost::enable_if<is_future_type<F1>,void>::type wait_for_all(F1& f1, Fs&... fs)
  56. {
  57. bool dummy[] = { (f1.wait(), true), (fs.wait(), true)... };
  58. // prevent unused parameter warning
  59. (void) dummy;
  60. }
  61. #endif // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)}
  62. }
  63. #endif // header