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:
parent
a3d6c5d3bc
commit
1e7da048d4
|
@ -42,7 +42,7 @@ int main(int argc, char* argv[]) {
|
||||||
if (!files.empty()) {
|
if (!files.empty()) {
|
||||||
vector<future<pair<string, optional<Yerbacon::Exception>>>> Units;
|
vector<future<pair<string, optional<Yerbacon::Exception>>>> Units;
|
||||||
const launch& Policy = not parallel ? launch::deferred : launch::async;
|
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]() {
|
Units.push_back(async(Policy, [&fileName, &compile]() {
|
||||||
pair<string, optional<Yerbacon::Exception>> resultingPair;
|
pair<string, optional<Yerbacon::Exception>> resultingPair;
|
||||||
try {
|
try {
|
||||||
|
@ -65,9 +65,9 @@ int main(int argc, char* argv[]) {
|
||||||
}
|
}
|
||||||
return resultingPair;
|
return resultingPair;
|
||||||
}));
|
}));
|
||||||
}
|
});
|
||||||
if (printResult) cout << "~~~~[Yerbacon compilation result]~~~~\n\n";
|
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();
|
const auto&& result = currentFuture.get();
|
||||||
if (not result.second.has_value()) {
|
if (not result.second.has_value()) {
|
||||||
if (printResult) cout << result.first;
|
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 << "Compilation of " << result.first << " has failed with the following error:\n" << result.second.value().what();
|
||||||
}
|
}
|
||||||
cout << "\n\n";
|
cout << "\n\n";
|
||||||
}
|
});
|
||||||
} else cout << "No valid file provided.\n";
|
} else cout << "No valid file provided.\n";
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
Loading…
Reference in New Issue