diff --git a/2022/25.cpp b/2022/25.cpp index 013117e..1f6db08 100644 --- a/2022/25.cpp +++ b/2022/25.cpp @@ -13,6 +13,8 @@ namespace { +using It = std::istream_iterator; + // template auto DivMod(T dividend, T divisor) -> std::pair @@ -59,8 +61,7 @@ auto ToInt(std::string const& str) -> T auto Solve(std::istream & in) -> std::string { - using It = std::istream_iterator; - return FromInt(std::transform_reduce(It(in), It(), 0, std::plus(), ToInt)); + return FromInt(std::transform_reduce(It{in}, It{}, std::int64_t{}, std::plus(), ToInt)); } } // namespace diff --git a/lib/include/aocpp/Startup.hpp b/lib/include/aocpp/Startup.hpp index 01c612f..b97f14e 100644 --- a/lib/include/aocpp/Startup.hpp +++ b/lib/include/aocpp/Startup.hpp @@ -8,17 +8,7 @@ namespace aocpp { -class ConditionalDeleter { - bool should_delete_; - -public: - ConditionalDeleter(bool should_delete) : should_delete_ {should_delete} {} - - template - auto operator()(T * pointer) -> void { if (should_delete_) { delete pointer; }} -}; - -auto Startup(int argc, char ** argv) -> std::unique_ptr; +auto Startup(int argc, char ** argv) -> std::unique_ptr; } diff --git a/lib/src/Startup.cpp b/lib/src/Startup.cpp index fbc249b..51b9570 100644 --- a/lib/src/Startup.cpp +++ b/lib/src/Startup.cpp @@ -12,29 +12,20 @@ namespace aocpp { -auto Startup(int argc, char ** argv) -> std::unique_ptr { +auto Startup(int argc, char ** argv) -> std::unique_ptr { if (std::getenv("DOCTEST")) { exit(doctest::Context{argc, argv}.run()); } - bool should_delete; - std::istream* result_ptr; - switch (argc) { case 2: - should_delete = true; - result_ptr = new std::ifstream{argv[1]}; - break; + return {new std::ifstream{argv[1]}, [](std::istream* p) { delete p; }}; case 1: - should_delete = false; - result_ptr = &std::cin; - break; + return {&std::cin, [](std::istream*){}}; default: std::cerr << "bad arguments\n"; exit(EXIT_FAILURE); } - - return {result_ptr, should_delete}; } }