## Class template line_counting_iterator

hamigaki::line_counting_iterator —

反復子に行数を数える機能を追加する

## Synopsis

    template<typename Iterator>
    class line_counting_iterator {
    public:
      // types
      typedef typename std::iterator_traits<Iterator>::value_type      value_type;
      typedef typename std::iterator_traits<Iterator>::reference       reference;
      typedef typename std::iterator_traits<Iterator>::pointer         pointer;
      typedef typename std::iterator_traits<Iterator>::difference_type difference_type;
      typedef /* see below */                                          iterator_category;

      // construct/copy/destruct
      line_counting_iterator();
      line_counting_iterator(const Iterator&);
      line_counting_iterator(const Iterator&, int);
      line_counting_iterator(const Iterator&, int, value_type);

      // operators
      reference operator*() const;
      line_counting_iterator<Iterator>& operator++();
      line_counting_iterator<Iterator>& operator--();

      // queries
      const Iterator& base() const;
      int line() const;

      private: Iterator current;
      private: int lines;
      private: value_type newline;
    };

## Description

`iterator_category`は、`typename std::iterator_traits<Iterator>::iterator_category`に応じて次のように決定される。

`iterator_traits<Iterator>::iterator_category` | `iterator_category`
--- | ---
`std::random_access_iterator_tag` | `std::bidirectional_iterator_tag`
`std::bidirectional_iterator_tag` | `std::bidirectional_iterator_tag`
`std::forward_iterator_tag` | `std::forward_iterator_tag`
`std::input_iterator_tag` | `std::input_iterator_tag`

### `line_counting_iterator` construct/copy/destruct

1.     line_counting_iterator();

   Effects: |
       current = Iterator();
       lines = -1;
       newline = '\n';

2.     line_counting_iterator(const Iterator& it);

   Effects: |
       current = it;
       lines = -1;
       newline = '\n';

3.     line_counting_iterator(const Iterator& it, int line);

   Effects: |
       current = it;
       lines = line;
       newline = '\n';

4.     line_counting_iterator(const Iterator& it, int line, value_type nl);

   Effects: |
       current = it;
       lines = line;
       newline = nl;

### `line_counting_iterator` operators

1.     reference operator*() const;

   Returns: | `*current`

2.     line_counting_iterator<Iterator>& operator++();

   Effects: |
       if (*current == newline)
           ++lines;
       ++current;
   Returns: | `*this`

3.     line_counting_iterator<Iterator>& operator--();

   Effects: |
       --current;
       if (*current == newline)
           --lines;
   Returns: | `*this`

### `line_counting_iterator` queries

1.     const Iterator& base() const;

   Returns: | `current`

2.     int line() const;

   Returns: | `lines`

| 製作著作 © 2006, 2007 Takeshi Mouri