Dereferencing adaptor?

M

Matthias

Hi,

again, I have a problem using containers of pointers (I'm near to the
point to drop them alltogether and work on usual containers instead...).

The problem is, if I want to perform some action on an element in a
normal container (normal means everyhing-but-a-pointer), I can do
something like this:

for_each( coll.begin(), coll.end(), do_something );

Same for sorting:

partition( coll.begin(), coll.end(), Predicate() );

Now, what if coll is a collection of pointers? The predicate will give
strange results, because it looks only at addresses.
So, instead of rewriting the predicate to work with pointers, is there
some kind of dereferencing adaptor already available, which allows me to
do this:

partition( coll.begin(), coll.end(), Dereference( Predicate() ) );

or something similar?
 
J

Jonathan Turkanis

Matthias said:
Now, what if coll is a collection of pointers? The predicate will give
strange results, because it looks only at addresses.
So, instead of rewriting the predicate to work with pointers, is there
some kind of dereferencing adaptor already available, which allows me
to do this:

partition( coll.begin(), coll.end(), Dereference( Predicate() ) );

or something similar?

Try boost's indirect_iterator:

http://www.boost.org/libs/iterator/doc/indirect_iterator.html

Jonathan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,234
Latest member
SkyeWeems

Latest Threads

Top