34auto when_all(std::vector<std::future<T>>& futures) -> std::vector<T>
36 std::vector<T> results;
37 results.reserve(futures.size());
38 std::exception_ptr first_error;
40 for (
auto& f : futures)
44 results.push_back(f.get());
49 first_error = std::current_exception();
50 results.emplace_back();
55 std::rethrow_exception(first_error);
65inline void when_all(std::vector<std::future<void>>& futures)
67 std::exception_ptr first_error;
69 for (
auto& f : futures)
78 first_error = std::current_exception();
83 std::rethrow_exception(first_error);
96 -> std::vector<expected<T, std::exception_ptr>>
98 std::vector<expected<T, std::exception_ptr>> results;
99 results.reserve(futures.size());
101 for (
auto& f : futures)
105 results.push_back(f.get());
109 results.push_back(
unexpected(std::current_exception()));
120 -> std::vector<expected<void, std::exception_ptr>>
122 std::vector<expected<void, std::exception_ptr>> results;
123 results.reserve(futures.size());
125 for (
auto& f : futures)
130 results.emplace_back();
134 results.push_back(
unexpected(std::current_exception()));
154auto when_any(std::vector<std::future<T>>& futures) -> std::pair<size_t, T>
158 for (
size_t i = 0; i < futures.size(); ++i)
160 if (futures[i].wait_for(std::chrono::milliseconds(1)) == std::future_status::ready)
161 return {i, futures[i].get()};
171inline auto when_any(std::vector<std::future<void>>& futures) ->
size_t
175 for (
size_t i = 0; i < futures.size(); ++i)
177 if (futures[i].wait_for(std::chrono::milliseconds(1)) == std::future_status::ready)
Exception thrown by expected::value() when the object is in the error state.
Polyfill for std::expected (C++23) for pre-C++23 compilers.
auto when_all(std::vector< std::future< T > > &futures) -> std::vector< T >
Block until all futures complete, returning results in submission order.
auto when_all_settled(std::vector< std::future< T > > &futures) -> std::vector< expected< T, std::exception_ptr > >
Block until all futures complete, returning an expected per slot.
auto when_any(std::vector< std::future< T > > &futures) -> std::pair< size_t, T >
Block until the first future becomes ready.