An output iterator that counts the number of objects written to it and discards them.
| 364 | // An output iterator that counts the number of objects written to it and |
| 365 | // discards them. |
| 366 | class counting_iterator { |
| 367 | private: |
| 368 | std::size_t count_; |
| 369 | |
| 370 | public: |
| 371 | using iterator_category = std::output_iterator_tag; |
| 372 | using difference_type = std::ptrdiff_t; |
| 373 | using pointer = void; |
| 374 | using reference = void; |
| 375 | using _Unchecked_type = counting_iterator; // Mark iterator as checked. |
| 376 | |
| 377 | struct value_type { |
| 378 | template <typename T> void operator=(const T&) {} |
| 379 | }; |
| 380 | |
| 381 | counting_iterator() : count_(0) {} |
| 382 | |
| 383 | std::size_t count() const { return count_; } |
| 384 | |
| 385 | counting_iterator& operator++() { |
| 386 | ++count_; |
| 387 | return *this; |
| 388 | } |
| 389 | |
| 390 | counting_iterator operator++(int) { |
| 391 | auto it = *this; |
| 392 | ++*this; |
| 393 | return it; |
| 394 | } |
| 395 | |
| 396 | value_type operator*() const { return {}; } |
| 397 | }; |
| 398 | |
| 399 | template <typename OutputIt> class truncating_iterator_base { |
| 400 | protected: |
no outgoing calls
no test coverage detected