Thread System
0.3.1
High-performance C++20 thread pool with work stealing and DAG scheduling
Loading...
Searching...
No Matches
batch_operations.h
Go to the documentation of this file.
1
// BSD 3-Clause License
2
// Copyright (c) 2024, 🍀☀🌕🌥 🌊
3
// See the LICENSE file in the project root for full license information.
4
5
#pragma once
6
19
#include <future>
20
#include <vector>
21
#include <utility>
22
#include <type_traits>
23
24
namespace
kcenon::thread
{
25
26
namespace
detail {
27
44
template
<
typename
Container,
typename
Operation>
45
auto
batch_apply
(Container&& items, Operation&& op)
46
{
47
using
ResultType =
decltype
(op(std::move(*std::begin(items))));
48
std::vector<ResultType> results;
49
results.reserve(items.size());
50
51
for
(
auto
&& item : items) {
52
results.push_back(op(std::move(item)));
53
}
54
55
return
results;
56
}
57
82
template
<
typename
T>
83
auto
collect_all
(std::vector<std::future<T>>& futures) -> std::vector<T>
84
{
85
std::vector<T> results;
86
results.reserve(futures.size());
87
88
for
(
auto
& future : futures) {
89
results.push_back(future.get());
90
}
91
92
return
results;
93
}
94
103
inline
void
collect_all
(std::vector<std::future<void>>& futures)
104
{
105
for
(
auto
& future : futures) {
106
future.get();
107
}
108
}
109
110
}
// namespace detail
111
112
}
// namespace kcenon::thread
kcenon::thread::detail::collect_all
auto collect_all(std::vector< std::future< T > > &futures) -> std::vector< T >
Collect all results from a vector of futures.
Definition
batch_operations.h:83
kcenon::thread::detail::batch_apply
auto batch_apply(Container &&items, Operation &&op)
Apply an operation to each item in a collection, returning results.
Definition
batch_operations.h:45
kcenon::thread
Core threading foundation of the thread system library.
Definition
thread_impl.h:17
include
kcenon
thread
utils
batch_operations.h
Generated by
1.12.0