Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
future_utils.H
Go to the documentation of this file.
1
2/*
3 Aleph_w
4
5 Data structures & Algorithms
6 version 2.0.0b
7 https://github.com/lrleon/Aleph-w
8
9 This file is part of Aleph-w library
10
11 Copyright (c) 2002-2026 Leandro Rabindranath Leon
12
13 Permission is hereby granted, free of charge, to any person obtaining a copy
14 of this software and associated documentation files (the "Software"), to deal
15 in the Software without restriction, including without limitation the rights
16 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17 copies of the Software, and to permit persons to whom the Software is
18 furnished to do so, subject to the following conditions:
19
20 The above copyright notice and this permission notice shall be included in all
21 copies or substantial portions of the Software.
22
23 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 SOFTWARE.
30*/
31
32
33#ifndef FUTURE_UTILS_H
34#define FUTURE_UTILS_H
35
36#include <future>
37#include <tpl_dynList.H>
38
67namespace Aleph
68{
69
92template <typename T>
93[[nodiscard]] inline DynList<T>
95{
97 while (!future_list.is_empty())
99
100 return ret;
101}
102
117template <typename T>
118[[nodiscard]] inline DynList<T>
119get_futures(DynList<std::future<T>> && future_list)
120{
121 return get_futures(future_list);
122}
123
139inline void get_futures(DynList<std::future<void>> & future_list)
140{
141 while (!future_list.is_empty())
143}
144
155inline void get_futures(DynList<std::future<void>> && future_list)
156{
158}
159
172template <typename T>
173[[nodiscard]] inline bool
174all_ready(DynList<std::future<T>> & future_list)
175{
176 for (auto it = future_list.get_it(); it.has_curr(); it.next())
177 if (it.get_curr().wait_for(std::chrono::seconds(0)) != std::future_status::ready)
178 return false;
179 return true;
180}
181
192template <typename T>
193[[nodiscard]] inline size_t
195{
196 size_t count = 0;
197 for (auto it = future_list.get_it(); it.has_curr(); it.next())
198 if (it.get_curr().wait_for(std::chrono::seconds(0)) == std::future_status::ready)
199 ++count;
200 return count;
201}
202
203} // end namespace Aleph
204
205#endif // FUTURE_UTILS_H
Dynamic singly linked list with functional programming support.
Definition htlist.H:1423
T & append(const T &item)
Append a new item by copy.
Definition htlist.H:1562
constexpr bool is_empty() const noexcept
Return true if list is empty.
Definition htlist.H:523
auto get_it() const
Return a properly initialized iterator positioned at the first item on the container.
Definition ah-dry.H:190
Main namespace for Aleph-w library functions.
Definition ah-arena.H:89
size_t count_ready(DynList< std::future< T > > &future_list)
Count how many futures are ready.
DynList< T > get_futures(DynList< std::future< T > > &future_list)
Collect results from a list of futures.
bool all_ready(DynList< std::future< T > > &future_list)
Check if all futures in a list are ready.
DynList< T > maps(const C &c, Op op)
Classic map operation.
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
Definition ahAlgo.H:127
Alias for htlist.H (DynList implementation).