Call std::for_each in main.cpp instead of using range-based loops, to allow the use of the parallel mode

This commit is contained in:
Username404-59 2021-10-05 08:36:15 +02:00
parent a3d6c5d3bc
commit 1e7da048d4
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1
1 changed files with 4 additions and 4 deletions

View File

@ -42,7 +42,7 @@ int main(int argc, char* argv[]) {
if (!files.empty()) {
vector<future<pair<string, optional<Yerbacon::Exception>>>> 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<string, optional<Yerbacon::Exception>> resultingPair;
try {
@ -65,9 +65,9 @@ int main(int argc, char* argv[]) {
}
return resultingPair;
}));
}
});
if (printResult) cout << "~~~~[Yerbacon compilation result]~~~~\n\n";
for (future<pair<string, optional<Yerbacon::Exception>>>& currentFuture: Units) {
for_each(Units.begin(), Units.end(), [&printResult](future<pair<string, optional<Yerbacon::Exception>>>& 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;
}