diff --git a/lib/include/aocpp/Counter.hpp b/lib/include/aocpp/Counter.hpp index e257db5..a23dace 100644 --- a/lib/include/aocpp/Counter.hpp +++ b/lib/include/aocpp/Counter.hpp @@ -6,25 +6,45 @@ template struct Counter { - using value_type = T; - using difference_type = std::ptrdiff_t; - using pointer = T*; - using reference = T&; - using iterator_category = std::output_iterator_tag; + using difference_type = std::ptrdiff_t; struct EmptyRef { - auto operator=(T const&) const -> void { } + auto operator=(T const&) const -> void {} + auto operator=(T && ) const -> void {} }; std::size_t n; - - auto operator++() -> Counter& { n++; return *this; } - auto operator++(int) -> Counter { Counter temp; n++; return temp; } - auto operator*() const -> EmptyRef { return EmptyRef{}; } - auto operator-(Counter const& rhs) const -> std::ptrdiff_t { - return std::ptrdiff_t{n} - std::ptrdiff_t{rhs.n}; + + Counter() : n{0} {} + Counter(std::size_t n) : n{n} {} + + auto operator++() -> Counter& + { + n++; + return *this; + } + + auto operator++(int) -> Counter + { + auto temp = *this; + n++; + return temp; + } + + auto operator*() const -> EmptyRef + { + return {}; + } + + auto operator-(Counter rhs) const -> difference_type + { + return difference_type{n} - difference_type{rhs}; + } + + operator std::size_t() const + { + return n; } - operator std::size_t() const { return n; } }; static_assert(std::output_iterator, int>);