diff --git a/2023/04.cpp b/2023/04.cpp index eac9bfb..e1395fa 100644 --- a/2023/04.cpp +++ b/2023/04.cpp @@ -54,7 +54,7 @@ auto CountWins(std::vector& cards) -> std::vector std::set_intersection( card.mine .begin(), card.mine .end(), card.winners.begin(), card.winners.end(), - Counter{}); + Counter{}); result.push_back(counter); } diff --git a/lib/include/aocpp/Counter.hpp b/lib/include/aocpp/Counter.hpp index 98ca576..0e3e87d 100644 --- a/lib/include/aocpp/Counter.hpp +++ b/lib/include/aocpp/Counter.hpp @@ -3,20 +3,20 @@ #include #include -template +/// @brief Output iterator that only counts the number of outputs. struct Counter { using difference_type = std::ptrdiff_t; struct EmptyRef { - auto operator=(T const&) const -> void {} - auto operator=(T && ) const -> void {} + template + auto operator=(T&&) const -> void {} }; - std::size_t n; + std::size_t n = 0; - Counter() : n{0} {} - Counter(std::size_t n) : n{n} {} + Counter() = default; + constexpr Counter(std::size_t n) : n{n} {} // prefix increment auto operator++() -> Counter& @@ -38,7 +38,7 @@ struct Counter auto operator-(Counter rhs) const -> difference_type { - return difference_type{n} - difference_type{rhs}; + return static_cast(n) - static_cast(rhs); } operator std::size_t() const @@ -47,4 +47,4 @@ struct Counter } }; -static_assert(std::output_iterator, int>); +static_assert(std::output_iterator);