
I resurect an old post : David Abrahams a écrit :
Simon Buchan <simon@hand-multimedia.co.nz> writes:
The idea is to define a template class, [...] which overloads operator*() and operator->() to access the element named "first" of the object returned by Iterator::operator*(). (With something analagous for second_iterator_t.) A function named first_iterator() provides a convenient creation function a-la std::make_pair(). [...] struct get_first { template <class T> typename T::first_type& operator()(T& x) const { return x.first; }
template <class T> typename T::first_type const& operator()(T const& x) const { return x.first; } };
// similar get_second
transform_iterator<get_first, Iterator>
Hello, I think this kind of adapter is quite usefull and of broad usage, and I think it should be part of the iterators provided by default in the Iterator library, just like indirect_iterator. Or at least put is as a real life example of what can be done with transform_iterator. Regards, -- Loïc