Boost logo

Boost :

From: Gennadiy Rozental (gennadiy.rozental_at_[hidden])
Date: 2004-05-23 05:44:47


Here is the input_iterator_facade template (similar in nature to Vladimir's
eof_iterator ) I am using in Boost.Test development:

namespace detail {

template<typename T>
struct value_type_ident
    typedef T value_type;

template<typename T>
struct ref_type_ident
    typedef T reference;

} // namespace detail

typename ImplPolicy,
typename Derived = mpl::void_,
typename ValueType = mpl::void_,
typename Reference = mpl::void_>
class input_iterator_facade
: public iterator_facade<
ype> >::type::value_type,
e> >::type::reference>
    // Constructor
    explicit input_iterator_facade( ImplPolicy const& p =
ImplPolicy() )
    : m_policy( p )
        m_valid = m_policy.initialize();


    //!! copy constructor/assignment - should we make rhs invalid after
    //!! do we need reset method?

protected: // provide access to the derived
    // Data members
    ImplPolicy m_policy;

    friend class iterator_core_access;

    // iterator facade interface implementation
    void increment()
        if( m_valid )
            m_valid = m_policy.get();
    bool equal( input_iterator_facade const& rhs ) const
         return !m_valid && !rhs.m_valid || m_valid && rhs.m_valid &&
m_policy.equal( rhs.m_policy );
    reference dereference() const
          return m_policy.dereference( m_valid );

    // Data members
    bool m_valid;

See full versions with extra comments here:

There is one specific iterator implemented that used this template located
in the same directory (more coming).
I actually combine new CRTP and old policy technique here, for later allows
me to implement more functionality in common code. Is there interest in
adding this to the family of iterator helpers?

Or could I move it in boost namespace for convenience?


Boost list run by bdawes at, gregod at, cpdaniel at, john at