input_iterator_facade (was: Re: [iterator facade] Why is dereference const?)

Hi, 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 template< typename ImplPolicy, typename Derived = mpl::void_, typename ValueType = mpl::void_, typename Reference = mpl::void_> class input_iterator_facade : public iterator_facade< typename mpl::if_<mpl::is_void_<Derived>,input_iterator_facade<ImplPolicy>,Derived>:: type, typename mpl::if_<mpl::is_void_<ValueType>,ImplPolicy,detail::value_type_ident<ValueT ype> >::type::value_type, forward_traversal_tag, typename mpl::if_<mpl::is_void_<Reference>,ImplPolicy,detail::ref_type_ident<Referenc e> >::type::reference> { public: // Constructor explicit input_iterator_facade( ImplPolicy const& p = ImplPolicy() ) : m_policy( p ) { m_valid = m_policy.initialize(); increment(); } //!! copy constructor/assignment - should we make rhs invalid after copy?? //!! do we need reset method? protected: // provide access to the derived // Data members ImplPolicy m_policy; private: 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: http://tinyurl.com/2x69z 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? Gennadiy.

"Gennadiy Rozental" <gennadiy.rozental@thomson.com> writes:
Hi,
Here is the input_iterator_facade template (similar in nature to Vladimir's eof_iterator ) I am using in Boost.Test development:
Hint 1: most mailers will strip tabs; not sure if you have any but there seem to be some missing indents Hint 1.5: if you have tabs in boost source, they should be removed ;-) Hint 2: post your code as an attachment, and mailers won't introduce problematic line wraps that make it invalid Cheers, -- Dave Abrahams Boost Consulting http://www.boost-consulting.com

Hi,
Here is the input_iterator_facade template (similar in nature to Vladimir's eof_iterator ) I am using in Boost.Test development:
Hint 1: most mailers will strip tabs; not sure if you have any but there seem to be some missing indents
Hint 1.5: if you have tabs in boost source, they should be removed ;-)
Hint 2: post your code as an attachment, and mailers won't introduce problematic line wraps that make it invalid
Link to the code is in original port. I presented body since it's small to simplify discussion. Gennadiy. P.S. And I do not have tabs in my code.

"Gennadiy Rozental" <gennadiy.rozental@thomson.com> writes:
Hi,
Here is the input_iterator_facade template (similar in nature to Vladimir's eof_iterator ) I am using in Boost.Test development:
Hint 1: most mailers will strip tabs; not sure if you have any but there seem to be some missing indents
Hint 1.5: if you have tabs in boost source, they should be removed ;-)
Hint 2: post your code as an attachment, and mailers won't introduce problematic line wraps that make it invalid
Link to the code is in original port.
I missed it because it was below the hard-to-read stuff.
I presented body since it's small to simplify discussion.
OK, no biggie; I guess it was big enough to cause a problem for me, though: I missed the link to the readable version.
Gennadiy.
P.S. And I do not have tabs in my code.
Like I said, I couldn't tell for sure. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com

Gennadiy Rozental wrote:
Hi,
Here is the input_iterator_facade template (similar in nature to Vladimir's eof_iterator ) I am using in Boost.Test development:
Funny -- I see that you use it to create line_iterator -- which was exactly the motivation for eof_iterator. My version of line_iterator is at: http://zigzag.cs.msu.su:7813/iterators/line_iterator.hpp
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?
I still don't understand which design, yours or mine, is better. It seems mine allows to create iterators with smaller number of lines, but maybe there's something else. The question arises because eof_iterator is already in CVS as part of program_options, and we surely can't add them both to iterators library.... - Volodya
participants (3)
-
David Abrahams
-
Gennadiy Rozental
-
Vladimir Prus