C++ Extensions (cppx) Documentation Internal Version
Main | Namespaces | Classes | NamespaceMembers | ClassMembers | Files

stdx::TransformItr Class Template Reference

template<class I, class R, class C>
class stdx::TransformItr< I, R, C >

When working with STL containers of objects it is common to want to look at only one member in a class. For example, if we have a person class which contains names and occupations we might want to only print each object's name or we might want to find a specific object based on a occupation. To do this with straight STL we need to write our own little function objects. A transform iterator can do the same thing by wrapping a standard iterator such that a member function gets called on every dereference. For example, we could make a container of person objects look like a container of names. The code below uses a transform iterator to print out all the names of person objects and then finds the first person with the name "Jim Smith".

 list<Person> lst;
 // ... fill lst with Person objects ...

 // Copy each person's name to standard out
 copy( trans_iseq(lst,&Person::getName), ostream_iterator<string>(cout,"\n") );

 // Find first person with name "Jim Smith"
 lst<Person>::iteartor itr;
 itr = find( trans_iseq(lst,&Person::getName), "Jim Smith" ).base();

trans_iseq() is a helper function which creates an input sequence of two transform iterators from the given container and member function pointer. Notice the need for the call to the transform iterator's base() member function. This is because otherwise the find algorithm would return a transform iterator, but what we really want is a basic lst<Person>::iterator - or in other words the iterator which the transform iterator wraps.

Normal function pointers and function objects are not allowed as arguments to the trasform iterator constructor.

List of all members.

Public Types

Public Methods

Detailed Documentation

Member Typedef Documentation

template<class I, class R, class C>
typedef I stdx::TransformItr::base_iterator
 

template<class I, class R, class C>
typedef std::iterator_traits<I>::iterator_category stdx::TransformItr::iterator_category
 

template<class I, class R, class C>
typedef R stdx::TransformItr::value_type
 

template<class I, class R, class C>
typedef std::iterator_traits<I>::difference_type stdx::TransformItr::difference_type
 

template<class I, class R, class C>
typedef R* stdx::TransformItr::pointer
 

template<class I, class R, class C>
typedef R& stdx::TransformItr::reference
 

Constructor & Destructor Documentation

template<class I, class R, class C>
stdx::TransformItr< I, R, C >::TransformItr  
 

Default transform iterator constructor which creates an end-of-container marker.

template<class I, class R, class C>
stdx::TransformItr< I, R, C >::TransformItr   baseItr,
R(C::*    p)()
[explicit]
 

Primary transform iterator constructor which creates a transform iterator wrapped around the given base iterator. The The given member function will be called for the object that the base iterator points to each time the transform iterator is dereferenced. Normal function pointers and function objects are not suitable arguments for this second parameter.

Member Function Documentation

template<class I, class R, class C>
value_type stdx::TransformItr< I, R, C >::operator *   const
 

template<class I, class R, class C>
pointer stdx::TransformItr< I, R, C >::operator->   const
 

template<class I, class R, class C>
reference stdx::TransformItr< I, R, C >::operator[] difference_type    n const
 

template<class I, class R, class C>
TransformItr<I,R,C> stdx::TransformItr< I, R, C >::operator+ difference_type    n const
 

template<class I, class R, class C>
TransformItr<I,R,C>& stdx::TransformItr< I, R, C >::operator+= difference_type    n
 

template<class I, class R, class C>
TransformItr<I,R,C> stdx::TransformItr< I, R, C >::operator- difference_type    n const
 

template<class I, class R, class C>
TransformItr<I,R,C>& stdx::TransformItr< I, R, C >::operator-= difference_type    n
 

template<class I, class R, class C>
TransformItr<I,R,C> stdx::TransformItr< I, R, C >::operator++ int   
 

template<class I, class R, class C>
TransformItr<I,R,C>& stdx::TransformItr< I, R, C >::operator++  
 

template<class I, class R, class C>
TransformItr<I,R,C> stdx::TransformItr< I, R, C >::operator-- int   
 

template<class I, class R, class C>
TransformItr<I,R,C>& stdx::TransformItr< I, R, C >::operator--  
 

template<class I, class R, class C>
I stdx::TransformItr< I, R, C >::base   const
 



The documentation for this class was generated from the following file:
Generated on Mon Aug 15 21:43:10 2005 by Doxygen 1.2.13-20020210 written by Dimitri van Heesch © 1997-2002