Boost C++ Libraries of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.

The line position iterator

The line_pos_iterator is a lightweight line position iterator. This iterator adapter only stores the current line number, nothing else. Unlike Spirit.Classic's position_iterator, it does not store the column number and does not need an end iterator. The current column can be computed, if needed.

Class Reference

template <class Iterator>
class line_pos_iterator : public boost::iterator_adaptor<
    line_pos_iterator<Iterator>  // Derived
  , Iterator                     // Base
  , boost::use_default           // Value
  , boost::forward_traversal_tag // CategoryOrTraversal
> {

    explicit line_pos_iterator(Iterator);

    std::size_t position() const;

    friend class boost::iterator_core_access;

    void increment();

    std::size_t line; // The line position.
    typename std::iterator_traits<Iterator>::value_type prev;


template <class Iterator>
inline std::size_t get_line(Iterator);

Get the line position. Returns -1 if Iterator is not a line_pos_iterator.


template <class Iterator>
inline Iterator get_line_start(Iterator lower_bound, Iterator current);

Get an iterator to the beginning of the line. Applicable to any iterator.


template <class Iterator>
inline iterator_range<Iterator>
get_current_line(Iterator lower_bound, Iterator current,
                 Iterator upper_bound);

Get an iterator_range containing the current line. Applicable to any iterator.


template <class Iterator>
inline std::size_t get_column(Iterator lower_bound, Iterator current,
                              std::size_t tabs = 4);

Get the current column. Applicable to any iterator.