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
に応じて次のように決定される。
line_counting_iterator
construct/copy/destruct
-
line_counting_iterator();
Effects:
|
current = Iterator();
lines = -1;
newline = '\n';
|
-
line_counting_iterator(const Iterator& it);
Effects:
|
current = it;
lines = -1;
newline = '\n';
|
-
line_counting_iterator(const Iterator& it, int line);
Effects:
|
current = it;
lines = line;
newline = '\n';
|
-
line_counting_iterator(const Iterator& it, int line, value_type nl);
Effects:
|
current = it;
lines = line;
newline = nl;
|
line_counting_iterator
operators
-
reference operator*() const;
-
line_counting_iterator<Iterator>& operator++();
Effects:
|
if (*current == newline)
++lines;
++current;
|
Returns:
|
*this
|
-
line_counting_iterator<Iterator>& operator--();
Effects:
|
--current;
if (*current == newline)
--lines;
|
Returns:
|
*this
|
line_counting_iterator
queries
-
const Iterator& base() const;
-
int line() const;