From 1e7da048d4c135c215e61a8b6742dc62a6d56239 Mon Sep 17 00:00:00 2001 From: Username404-59 Date: Tue, 5 Oct 2021 08:36:15 +0200 Subject: [PATCH] Call std::for_each in main.cpp instead of using range-based loops, to allow the use of the parallel mode --- src/main.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 4a7acc9..b892019 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -42,7 +42,7 @@ int main(int argc, char* argv[]) { if (!files.empty()) { vector>>> Units; const launch& Policy = not parallel ? launch::deferred : launch::async; - for (const string_view& fileName: files) { + for_each(files.begin(), files.end(), [&Units, &Policy, &compile](const string_view& fileName){ Units.push_back(async(Policy, [&fileName, &compile]() { pair> resultingPair; try { @@ -65,9 +65,9 @@ int main(int argc, char* argv[]) { } return resultingPair; })); - } + }); if (printResult) cout << "~~~~[Yerbacon compilation result]~~~~\n\n"; - for (future>>& currentFuture: Units) { + for_each(Units.begin(), Units.end(), [&printResult](future>>& currentFuture) { const auto&& result = currentFuture.get(); if (not result.second.has_value()) { if (printResult) cout << result.first; @@ -75,7 +75,7 @@ int main(int argc, char* argv[]) { cout << "Compilation of " << result.first << " has failed with the following error:\n" << result.second.value().what(); } cout << "\n\n"; - } + }); } else cout << "No valid file provided.\n"; return EXIT_SUCCESS; } \ No newline at end of file