Use std::transform on the files set to output the results to the Units vector

This commit is contained in:
Username404-59 2021-10-05 09:05:50 +02:00
parent 24d934caf2
commit 70f93b9200
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1
1 changed files with 3 additions and 3 deletions

View File

@ -42,8 +42,8 @@ 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_each(files.begin(), files.end(), [&Units, &Policy, &compile](const string_view& fileName){ transform(files.begin(), files.end(), back_inserter(Units), [&Policy, &compile](const string_view& fileName){
Units.push_back(async(Policy, [&fileName, &compile]() { return async(Policy, [&fileName, &compile]() {
pair<string, optional<Yerbacon::Exception>> resultingPair; pair<string, optional<Yerbacon::Exception>> resultingPair;
try { try {
resultingPair.first = compile(fileName); resultingPair.first = compile(fileName);
@ -64,7 +64,7 @@ int main(int argc, char* argv[]) {
resultingPair.second.emplace(error); resultingPair.second.emplace(error);
} }
return resultingPair; return resultingPair;
})); });
}); });
if (printResult) cout << "~~~~[Yerbacon compilation result]~~~~\n\n"; if (printResult) cout << "~~~~[Yerbacon compilation result]~~~~\n\n";
for_each(Units.begin(), Units.end(), [&printResult](future<pair<string, optional<Yerbacon::Exception>>>& currentFuture) { for_each(Units.begin(), Units.end(), [&printResult](future<pair<string, optional<Yerbacon::Exception>>>& currentFuture) {