From 4340a7ccef1f622fe30d213bd7bd6b92ace08825 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 6 Feb 2022 17:03:12 +0000 Subject: unique_ptr over ScopeExit --- icespider/compile/routeCompiler.cpp | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/icespider/compile/routeCompiler.cpp b/icespider/compile/routeCompiler.cpp index da4f457..3a25d6e 100644 --- a/icespider/compile/routeCompiler.cpp +++ b/icespider/compile/routeCompiler.cpp @@ -193,22 +193,17 @@ namespace IceSpider { } }); - FILE * out = fopen(output.c_str(), "w"); - FILE * outh = fopen(outputh.c_str(), "w"); + using FilePtr = std::unique_ptr; + const auto out = FilePtr {fopen(output.c_str(), "w"), &fclose}; + const auto outh = FilePtr {fopen(outputh.c_str(), "w"), &fclose}; if (!out || !outh) { throw std::runtime_error("Failed to open output files"); } - AdHoc::ScopeExit outClose( - [out, outh]() { - fclose(out); - fclose(outh); - }, - nullptr, - [&output, &outputh]() { + AdHoc::ScopeExit outClose(nullptr, nullptr, [&output, &outputh]() { std::filesystem::remove(output); std::filesystem::remove(outputh); }); - processConfiguration(out, outh, output.stem().string(), configuration, units); + processConfiguration(out.get(), outh.get(), output.stem().string(), configuration, units); } RouteCompiler::Units -- cgit v1.2.3