diff options
| author | Dan Goodliffe <dan@randomdan.homeip.net> | 2022-02-06 17:03:12 +0000 | 
|---|---|---|
| committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2022-02-06 17:03:12 +0000 | 
| commit | 4340a7ccef1f622fe30d213bd7bd6b92ace08825 (patch) | |
| tree | 459833fa7ef7465d8653617c2aec7569808355dc | |
| parent | Install ice to new standard path (diff) | |
| download | icespider-4340a7ccef1f622fe30d213bd7bd6b92ace08825.tar.bz2 icespider-4340a7ccef1f622fe30d213bd7bd6b92ace08825.tar.xz icespider-4340a7ccef1f622fe30d213bd7bd6b92ace08825.zip  | |
unique_ptr over ScopeExit
| -rw-r--r-- | icespider/compile/routeCompiler.cpp | 15 | 
1 files 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<FILE, decltype(&fclose)>; +			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  | 
