Boost  v1.57.0
doxygen for www.boost.org
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
boost::eof_iterator< Derived, ValueType > Class Template Reference

The 'eof_iterator' class is useful for constructing forward iterators in cases where iterator extract data from some source and it's easy to detect 'eof' – i.e. More...

#include <eof_iterator.hpp>

Inheritance diagram for boost::eof_iterator< Derived, ValueType >:
Collaboration diagram for boost::eof_iterator< Derived, ValueType >:

Public Member Functions

 eof_iterator ()
 

Protected Member Functions

ValueType & value ()
 Returns the reference which should be used by derived class to store the next value. More...
 
void found_eof ()
 Should be called by derived class to indicate that it can't produce next element. More...
 

Friends

class iterator_core_access
 

Detailed Description

template<class Derived, class ValueType>
class boost::eof_iterator< Derived, ValueType >

The 'eof_iterator' class is useful for constructing forward iterators in cases where iterator extract data from some source and it's easy to detect 'eof' – i.e.

the situation where there's no data. One apparent example is reading lines from a file.

Implementing such iterators using 'iterator_facade' directly would require to create class with three core operation, a couple of constructors. When using 'eof_iterator', the derived class should define only one method to get new value, plus a couple of constructors.

The basic idea is that iterator has 'eof' bit. Two iterators are equal only if both have their 'eof' bits set. The 'get' method either obtains the new value or sets the 'eof' bit.

Specifically, derived class should define:

  1. A default constructor, which creates iterator with 'eof' bit set. The constructor body should call 'found_eof' method defined here.
  2. Some other constructor. It should initialize some 'data pointer' used in iterator operation and then call 'get'.
  3. The 'get' method. It should operate this way:
    • look at some 'data pointer' to see if new element is available; if not, it should call 'found_eof'.
    • extract new element and store it at location returned by the 'value' method.
    • advance the data pointer.

Essentially, the 'get' method has the functionality of both 'increment' and 'dereference'. It's very good for the cases where data extraction implicitly moves data pointer, like for stream operation.

Constructor & Destructor Documentation

template<class Derived, class ValueType>
boost::eof_iterator< Derived, ValueType >::eof_iterator ( )
inline

Member Function Documentation

template<class Derived, class ValueType>
void boost::eof_iterator< Derived, ValueType >::found_eof ( )
inlineprotected

Should be called by derived class to indicate that it can't produce next element.

template<class Derived, class ValueType>
ValueType& boost::eof_iterator< Derived, ValueType >::value ( )
inlineprotected

Returns the reference which should be used by derived class to store the next value.

Friends And Related Function Documentation

template<class Derived, class ValueType>
friend class iterator_core_access
friend

The documentation for this class was generated from the following file: