From df195e65b510b6ac5df15d1be09b3e649157e428 Mon Sep 17 00:00:00 2001 From: Eric Mertens Date: Tue, 31 Jan 2023 09:44:30 -0800 Subject: [PATCH] Don't bother supporting a filename --- 2017/12.cpp | 2 -- 2017/13.cpp | 2 -- 2017/17.cpp | 2 -- 2019/16.cpp | 1 - 2019/21.cpp | 1 - 2019/22.cpp | 1 - 2019/25.cpp | 1 - 2020/03.cpp | 1 - 2020/21.cpp | 1 - 2022/13.cpp | 4 ++-- lib/include/aocpp/Startup.hpp | 9 --------- lib/src/Startup.cpp | 26 +++++--------------------- 12 files changed, 7 insertions(+), 44 deletions(-) diff --git a/2017/12.cpp b/2017/12.cpp index 48dace1..8d59399 100644 --- a/2017/12.cpp +++ b/2017/12.cpp @@ -9,8 +9,6 @@ #include -using namespace aocpp; - namespace { auto Parse(std::istream & in) diff --git a/2017/13.cpp b/2017/13.cpp index 540954c..db64ba9 100644 --- a/2017/13.cpp +++ b/2017/13.cpp @@ -9,8 +9,6 @@ #include -using namespace aocpp; - namespace { struct Scanner { diff --git a/2017/17.cpp b/2017/17.cpp index a65d20b..6b2531d 100644 --- a/2017/17.cpp +++ b/2017/17.cpp @@ -6,8 +6,6 @@ #include -using namespace aocpp; - namespace { auto Step(std::vector & spin, int steps) -> void { diff --git a/2019/16.cpp b/2019/16.cpp index dd970dd..3358fe5 100644 --- a/2019/16.cpp +++ b/2019/16.cpp @@ -7,7 +7,6 @@ #include #include -using namespace aocpp; namespace { diff --git a/2019/21.cpp b/2019/21.cpp index d0921e3..df4560d 100644 --- a/2019/21.cpp +++ b/2019/21.cpp @@ -10,7 +10,6 @@ #include #include -using namespace aocpp; using namespace intcode; namespace { diff --git a/2019/22.cpp b/2019/22.cpp index 001784a..434ece5 100644 --- a/2019/22.cpp +++ b/2019/22.cpp @@ -7,7 +7,6 @@ #include #include using namespace zmod; -using namespace aocpp; template struct overloaded : Ts... { using Ts::operator()...; }; template overloaded(Ts...) -> overloaded; diff --git a/2019/25.cpp b/2019/25.cpp index 4dfa560..ceb9891 100644 --- a/2019/25.cpp +++ b/2019/25.cpp @@ -9,7 +9,6 @@ #include #include -using namespace aocpp; using namespace intcode; namespace { diff --git a/2020/03.cpp b/2020/03.cpp index c431d76..7d272ee 100644 --- a/2020/03.cpp +++ b/2020/03.cpp @@ -14,7 +14,6 @@ #include #include -using aocpp::Startup; using aocpp::Coord; using aocpp::Grid; diff --git a/2020/21.cpp b/2020/21.cpp index d0684e5..d30dd5d 100644 --- a/2020/21.cpp +++ b/2020/21.cpp @@ -17,7 +17,6 @@ #include #include -using aocpp::Startup; using aocpp::SplitOn; using dlx::Dlx; diff --git a/2022/13.cpp b/2022/13.cpp index b8320c7..3cc4d5f 100644 --- a/2022/13.cpp +++ b/2022/13.cpp @@ -47,7 +47,7 @@ auto ParseTree(std::string::iterator & begin, std::string::iterator end) -> Tree switch (*begin++) { case ',': goto top; case ']': return Tree{std::move(subtrees)}; - default: assert(false); + default: throw std::runtime_error{"bad tree list"}; } } else if (isdigit(*begin)) { auto number_end = std::find_if_not(begin, end, isdigit); @@ -56,7 +56,7 @@ auto ParseTree(std::string::iterator & begin, std::string::iterator end) -> Tree std::int64_t number = std::stoll(number_str); return Tree{number}; } else { - assert(false); + throw std::runtime_error{"bad tree start"}; } } diff --git a/lib/include/aocpp/Startup.hpp b/lib/include/aocpp/Startup.hpp index a13b68d..e5cec34 100644 --- a/lib/include/aocpp/Startup.hpp +++ b/lib/include/aocpp/Startup.hpp @@ -8,15 +8,6 @@ #include #include -namespace aocpp { - -/// @brief Return the selected input stream or run the test suite -/// @param argc Number of arguments -/// @param argv Command line arguments -auto Startup(int argc, char ** argv) -> std::unique_ptr; - -} - auto Main(std::istream & in, std::ostream & out) -> void; #endif diff --git a/lib/src/Startup.cpp b/lib/src/Startup.cpp index 15a3d0f..81df39a 100644 --- a/lib/src/Startup.cpp +++ b/lib/src/Startup.cpp @@ -10,30 +10,14 @@ #define DOCTEST_CONFIG_IMPLEMENT #include -namespace aocpp { - -auto Startup(int argc, char ** argv) -> std::unique_ptr { - if (std::getenv("DOCTEST")) { - exit(doctest::Context{argc, argv}.run()); - } - - switch (argc) { - case 2: - return {new std::ifstream{argv[1]}, [](std::istream* p) { delete p; }}; - case 1: - return {&std::cin, [](std::istream*){}}; - default: - std::cerr << "bad arguments\n"; - exit(EXIT_FAILURE); - } -} - -} - auto main(int argc, char ** argv) -> int { + if (std::getenv("DOCTEST")) { + return doctest::Context{argc, argv}.run(); + } + try { - Main(*aocpp::Startup(argc, argv), std::cout); + Main(std::cin, std::cout); } catch (std::exception const& e) { std::cerr << "Program failed: " << e.what() << std::endl; return 1;