From 8004218a7997270eecbb1e907d55272d9f6c39b5 Mon Sep 17 00:00:00 2001 From: Eric Mertens Date: Tue, 31 Jan 2023 20:46:03 -0800 Subject: [PATCH] remove unique_ptr from main --- lib/src/Startup.cpp | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/lib/src/Startup.cpp b/lib/src/Startup.cpp index fc5721c..78aaa81 100644 --- a/lib/src/Startup.cpp +++ b/lib/src/Startup.cpp @@ -2,10 +2,9 @@ #include #include -#include -#include #include #include + #include #define DOCTEST_CONFIG_IMPLEMENT @@ -41,27 +40,22 @@ auto main(int argc, char ** argv) -> int return doctest::Context{argc, argv}.run(); } - std::unique_ptr in - {in_name - ? decltype(in){new std::ifstream{in_name}, [](auto p) { delete p; }} - : decltype(in){&std::cin, [](auto){}}}; + std::ifstream fin; + std::ofstream fout; + std::istream & in {in_name ? fin = std::ifstream{in_name } : std::cin }; + std::ostream & out {out_name ? fout = std::ofstream{out_name} : std::cout}; - if (in->fail()) { + if (in.fail()) { std::cerr << "Bad input file" << std::endl; return 1; } - std::unique_ptr out - {out_name - ? decltype(out){new std::ofstream{out_name}, [](auto p) { delete p; }} - : decltype(out){&std::cout, [](auto){}}}; - - if (out->fail()) { + if (out.fail()) { std::cerr << "Bad output file" << std::endl; return 1; } - Main(*in, *out); + Main(in, out); } catch (std::exception const& e) { std::cerr << "Program failed: " << e.what() << std::endl; return 1;