Don't bother supporting a filename

This commit is contained in:
Eric Mertens 2023-01-31 09:44:30 -08:00
parent 2f7949b8da
commit df195e65b5
12 changed files with 7 additions and 44 deletions

View File

@ -9,8 +9,6 @@
#include <aocpp/Startup.hpp>
using namespace aocpp;
namespace {
auto Parse(std::istream & in)

View File

@ -9,8 +9,6 @@
#include <aocpp/Startup.hpp>
using namespace aocpp;
namespace {
struct Scanner {

View File

@ -6,8 +6,6 @@
#include <aocpp/Startup.hpp>
using namespace aocpp;
namespace {
auto Step(std::vector<std::uint32_t> & spin, int steps) -> void {

View File

@ -7,7 +7,6 @@
#include <doctest.h>
#include <aocpp/Startup.hpp>
using namespace aocpp;
namespace {

View File

@ -10,7 +10,6 @@
#include <aocpp/Startup.hpp>
#include <intcode/intcode.hpp>
using namespace aocpp;
using namespace intcode;
namespace {

View File

@ -7,7 +7,6 @@
#include <aocpp/Startup.hpp>
#include <zmod.hpp>
using namespace zmod;
using namespace aocpp;
template <class... Ts> struct overloaded : Ts... { using Ts::operator()...; };
template <class... Ts> overloaded(Ts...) -> overloaded<Ts...>;

View File

@ -9,7 +9,6 @@
#include <aocpp/Startup.hpp>
#include <intcode/intcode.hpp>
using namespace aocpp;
using namespace intcode;
namespace {

View File

@ -14,7 +14,6 @@
#include <aocpp/Grid.hpp>
#include <aocpp/Coord.hpp>
using aocpp::Startup;
using aocpp::Coord;
using aocpp::Grid;

View File

@ -17,7 +17,6 @@
#include <aocpp/Parsing.hpp>
#include <dlx.hpp>
using aocpp::Startup;
using aocpp::SplitOn;
using dlx::Dlx;

View File

@ -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"};
}
}

View File

@ -8,15 +8,6 @@
#include <memory>
#include <optional>
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<std::istream, void(*)(std::istream*)>;
}
auto Main(std::istream & in, std::ostream & out) -> void;
#endif

View File

@ -10,30 +10,14 @@
#define DOCTEST_CONFIG_IMPLEMENT
#include <doctest.h>
namespace aocpp {
auto Startup(int argc, char ** argv) -> std::unique_ptr<std::istream, void(*)(std::istream*)> {
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;