remove unique_ptr from main

This commit is contained in:
Eric Mertens 2023-01-31 20:46:03 -08:00
parent c074e66157
commit 8004218a79

View File

@ -2,10 +2,9 @@
#include <cstdlib>
#include <iostream>
#include <optional>
#include <memory>
#include <fstream>
#include <utility>
#include <unistd.h>
#define DOCTEST_CONFIG_IMPLEMENT
@ -41,27 +40,22 @@ auto main(int argc, char ** argv) -> int
return doctest::Context{argc, argv}.run();
}
std::unique_ptr<std::istream, void(*)(std::istream*)> 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<std::ostream, void(*)(std::ostream*)> 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;