From fbe8e189d31fd0fd3ed1de16f6c967f07664dd13 Mon Sep 17 00:00:00 2001 From: Username404 Date: Fri, 6 Aug 2021 11:58:43 +0200 Subject: [PATCH] Reuse a lambda in main.cpp. --- src/main.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 384f681..9e2d23d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -30,21 +30,24 @@ int main(int argc, char* argv[]) { else if (currentArg == Argument("parallel")) parallel = true; else if (currentArg.ends_with(".ybcon")) files.push_back(currentArg); } + const auto compile = [printResult, target](string_view& name) { + const string transpiledString = transpile(parseString(getFileContent(name.data())), target); + stringstream consoleOutput; + if (printResult) consoleOutput << "~~~~[Yerbacon compilation result]~~~~\n\n" << "[WIP]\n" << transpiledString << "\n\n"; + name.remove_suffix(6); + string outputFile; + (outputFile = name).append(target); + outputFileContent(outputFile, transpiledString); + return consoleOutput.str(); + }; if (!files.empty()) { const set uniqueFiles(files.begin(), files.end()); vector> Units; const launch& Policy = not parallel ? launch::deferred : launch::async; for (string_view fileName: uniqueFiles) { if (fileName != "none") { - future newAsync = async(Policy, [printResult, fileName, target]() mutable { - const string transpiledString = transpile(parseString(getFileContent(fileName.data())), target); - stringstream consoleOutput; - if (printResult) consoleOutput << "~~~~[Yerbacon compilation result]~~~~\n\n" << "[WIP]\n" << transpiledString << "\n\n"; - fileName.remove_suffix(6); - string outputFile; - (outputFile = fileName).append(target); - outputFileContent(outputFile, transpiledString); - return consoleOutput.str(); + future newAsync = async(Policy, [&fileName, &compile]() { + return compile(fileName); }); Units.push_back(move(newAsync)); }