-// An output iterator that counts the number of objects written to it and
-// discards them.
-class counting_iterator {
- private:
- size_t count_;
-
- public:
- using iterator_category = std::output_iterator_tag;
- using difference_type = std::ptrdiff_t;
- using pointer = void;
- using reference = void;
- using _Unchecked_type = counting_iterator; // Mark iterator as checked.
-
- struct value_type {
- template <typename T> void operator=(const T&) {}
- };
-
- counting_iterator() : count_(0) {}
-
- size_t count() const { return count_; }
-
- counting_iterator& operator++() {
- ++count_;
- return *this;
- }
- counting_iterator operator++(int) {
- auto it = *this;
- ++*this;
- return it;
- }
-
- friend counting_iterator operator+(counting_iterator it, difference_type n) {
- it.count_ += static_cast<size_t>(n);
- return it;
- }
-
- value_type operator*() const { return {}; }
-};
-