|
Boost : |
From: Eric Niebler (eric_at_[hidden])
Date: 2003-12-17 01:14:09
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?
-- Eric Niebler Boost Consulting www.boost-consulting.com (*) Actually, I didn't write this. Credit goes to Hartmut Kaiser, who helped me to get xpressive compiling with boost CVS.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk