|
Boost : |
From: the_dilster (dylan_at_[hidden])
Date: 2001-12-07 00:30:54
--- In boost_at_y..., "David Abrahams" <david.abrahams_at_r...> wrote:
>
> ----- Original Message -----
> From: "the_dilster" <dylan_at_m...>
> > Well it wasn't meant to be a final implementation, overriding the
> > value_type/pointer/reference typedef's is pretty straight forward
> > though. I don't see how this affects my problem with the current
> > iterator_adaptor library (specifically the use of
> > XXXgenerator<...>::type).
>
> Until the language has template typedefs, there's no way around it.
>
> If I had to choose between using a type generator and doing the
> pointer_iterator thing I'd always go for the type generator, but
you may
> have different criteria for success...
>
> -Dave
The generators don't help avoiding pointer_iterator - as I said it's
only needed if you want to use my member_iterator with a vector under
VC, because iterator_traits isn't specialised properly.
member_iterator should really be:
template <class T, class I, class C = iterator_traits<I>::value_type>
struct member_iterator : I
{
typedef iterator_traits<I>::iterator_category iterator_category;
typedef iterator<iterator_category, T>::value_type value_type;
typedef iterator<iterator_category, T>::pointer pointer;
typedef iterator<iterator_category, T>::reference reference;
member_iterator() { }
member_iterator(const I& i, T C::* m = 0) : I(i), m_member(m) { }
reference operator* () { return I::operator*().*m_member; }
private:
T C::* m_member;
};
The main 'trick' it relies on it determining the pointer class based
on the type of iterator, so the only thing you need to specify is the
member class and the iterator class:
member_iterator<string, list_iterator>
person_first(person.begin(), &person::m_name);
Actually what I would have loved to be able to do is:
member_iterator<&person::m_name, list_iterator>
person_first(person.begin());
Which would require "template templates" - unfortunately I don't see
that happening in the near future.
At any rate the point is the requirement to type (= remember!) as
little as possible to use the class.
Dylan
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk