remove template parameter from Counter

This commit is contained in:
Eric Mertens 2023-12-05 14:51:24 -08:00
parent ab86531dc5
commit 4073ac22fc
2 changed files with 9 additions and 9 deletions

View File

@ -54,7 +54,7 @@ auto CountWins(std::vector<Card>& cards) -> std::vector<std::size_t>
std::set_intersection( std::set_intersection(
card.mine .begin(), card.mine .end(), card.mine .begin(), card.mine .end(),
card.winners.begin(), card.winners.end(), card.winners.begin(), card.winners.end(),
Counter<std::size_t>{}); Counter{});
result.push_back(counter); result.push_back(counter);
} }

View File

@ -3,20 +3,20 @@
#include <cstdint> #include <cstdint>
#include <iterator> #include <iterator>
template <typename T> /// @brief Output iterator that only counts the number of outputs.
struct Counter struct Counter
{ {
using difference_type = std::ptrdiff_t; using difference_type = std::ptrdiff_t;
struct EmptyRef { struct EmptyRef {
auto operator=(T const&) const -> void {} template <typename T>
auto operator=(T&&) const -> void {} auto operator=(T&&) const -> void {}
}; };
std::size_t n; std::size_t n = 0;
Counter() : n{0} {} Counter() = default;
Counter(std::size_t n) : n{n} {} constexpr Counter(std::size_t n) : n{n} {}
// prefix increment // prefix increment
auto operator++() -> Counter& auto operator++() -> Counter&
@ -38,7 +38,7 @@ struct Counter
auto operator-(Counter rhs) const -> difference_type auto operator-(Counter rhs) const -> difference_type
{ {
return difference_type{n} - difference_type{rhs}; return static_cast<difference_type>(n) - static_cast<difference_type>(rhs);
} }
operator std::size_t() const operator std::size_t() const
@ -47,4 +47,4 @@ struct Counter
} }
}; };
static_assert(std::output_iterator<Counter<int>, int>); static_assert(std::output_iterator<Counter, int>);