By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,332 Members | 1,427 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,332 IT Pros & Developers. It's quick & easy.

Dereferencing adaptor?

P: n/a
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?

--
Regards,
Matthias
Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Matthias wrote:
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/d..._iterator.html

Jonathan
Jul 23 '05 #2

P: n/a
Jonathan Turkanis wrote:
Matthias wrote:

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/d..._iterator.html

Jonathan


Ah that looks like exactly what I need, thanks.

--
Regards,
Matthias
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.