Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2003-12-17 11:41:35


"Eric Niebler" <eric_at_[hidden]> writes:

> David Abrahams wrote:
>> It's hard to imagine that any use of the new iterator adaptors
>> should
>> require more code than the old library did. I don't see any .hpp
>> file patch either. What am I missing?
>>
>
> Perhaps I am just ignorant of how best to use the new iterator
> adaptors, but I have found that I need to write more code with the new
> IA lib than with the old. In xpressive, I wanted to make a derived
> const * look like a base const * (slicing off the derived portion).
> With the old iterators, it was a simple typedef:
>
> typedef ::boost::iterator_adaptor
> <
> derived const *,
> ::boost::default_iterator_policies,
> base,
> base const &,
> base const *
> >
> const_iterator;
>
> With the new iterators, I had to do define a class (with CRT!) and a
> typedef (*):
>
> template< typename ValueT, typename MainIterT >
> struct backref_iterator
> : ::boost::iterator_adaptor
> <
> backref_iterator< ValueT, MainIterT >,
> MainIterT,
> ValueT,
> std::random_access_iterator_tag
> >
> {
> typedef ::boost::iterator_adaptor
> <
> backref_iterator< ValueT, MainIterT >,
> MainIterT,
> ValueT,
> std::random_access_iterator_tag
> >
> base_t;
>
> backref_iterator( MainIterT baseiter )
> : base_t( baseiter )
> {
> }
> };
>
> typedef backref_iterator
> <
> base const,
> derived const *
> >
> const_iterator;
>
>
> Clearly I'm not making the best use of the new iterator adaptors,
> right? Or am I?

Well, OK. It's pretty unusual to have new iterators which can use the
default policies. And the CRTP does induce some syntax overhead. I
suppose we could supply an iterator adaptor generator which builds new
types from policies, for the cases where that works out. In the cases
where it doesn't, things get mighty ugly.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk