Files
Library/include/Void/Async/ParallelFor.hpp
T
faumarayandClaude Fable 5 28b94883fd Restructure into umbrella modules (~55 -> 16 targets)
Headers move, CMake targets merge, C++ namespaces stay unchanged:
- Core: Scope, Lazy, Counted, Flags, Hash, Bits, Uuid, TypeList, TypeMap, Variant
- Functional: Pipeline, Either, Result, Retry
- Containers: Ring, Pool, PriorityQueue, LRU, Trie, Graph, DisjointSet, Bitset, Interval
- Math: +Matrix, Numeric, Random, Histogram
- Text: Str, Format, Tokenizer, Diff, Encoding, Semver
- Data: Json, Csv, Ini
- Async: Coro, Concurrency, EventBus, Observable
- Time: +Bench
- Log: Log facade + Logging framework (facade now header-only, breaking
  the Stacktrace<->Log link cycle the merge would have created)
- System: FileSystem + Process
- Configuration: +Argparse
- Unchanged: Stacktrace, Plugin, StateMachine, Testing, TestingMock, Detail

Module system fixes:
- OPTIONAL_DEPS resolution deferred to void_finalize_modules() so it no
  longer depends on the alphabetical discovery order of src/ subdirs
  (Testing -> Text would have been silently dropped).
- Every header-only module now has a tracked module.cmake; previously the
  empty src/<Name> marker dirs were untracked, so a fresh clone would have
  silently skipped those modules.
- VOID_HAS_LOGGING/CONCURRENCY/STR consumers renamed to LOG/ASYNC/TEXT.

Tests move to tests/standalone/<Umbrella>/<Feature>.cpp (Result suite files
prefixed: ResultBasic etc.). Test count verified identical (831) before and
after. README/CLAUDE.md module tables updated.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-12 18:50:02 +03:00

38 lines
987 B
C++

#pragma once
#include <Void/Async/ThreadPool.hpp>
#include <concepts>
#include <future>
#include <vector>
namespace Void::Concurrency
{
// Submit one task per index in [first, last) to pool; block until all done.
// Exceptions from tasks propagate via std::future::get() to the caller.
template <std::integral I, std::invocable<I> F>
void parallel_for(I first, I last, F&& f, ThreadPool& pool)
{
if (first >= last) {
return;
}
std::vector<std::future<void>> futures;
futures.reserve(static_cast<std::size_t>(last - first));
for (auto i = first; i < last; ++i) {
futures.push_back(pool.submit([f, i] { f(i); }));
}
for (auto& fut : futures) {
fut.get();
}
}
// Convenience overload that creates a temporary pool sized to hardware
// concurrency.
template <std::integral I, std::invocable<I> F>
void parallel_for(I first, I last, F&& f)
{
ThreadPool pool;
parallel_for(first, last, std::forward<F>(f), pool);
}
} // namespace Void::Concurrency