473,383 Members | 1,815 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Dereferencing adaptor?

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
2 1421
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: FrodoBaggins | last post by:
Dear Team, I have set up a Windows Server 2003 on a laptop PC in order to experiment with Visual Studio .NET. On attempting to set up Active Directory, I get the message: "The wizard has...
4
by: Scott Smedley | last post by:
Hi all, I'm trying to write a special adaptor iterator for my program. I have *almost* succeeded, though it fails under some circumstances. See the for-loop in main(). Any pointers/help...
3
by: Stanislaw Salik | last post by:
Hi, Lets suppose we want to use generic algotithms on collections of pointers (both raw and smart). For example, we want to sort a vector of (smart)pointers. We need a comparator that will take...
51
by: BigMan | last post by:
Does the C++ standard define what should happen in case of NULL pointer dereferencing. If not, does it say that it is illegal? Where, if so, does it say it?
3
by: Matthias Kaeppler | last post by:
Hello, I need to sort a range of pointers with a predicate which applies to the pointees. I tried to use boost::indirect_iterator, however, this will sort the container with the pointees instead...
1
by: Tony Johansson | last post by:
Hello! I'm reading about design pattern adaptor in the GOF book and there is something that sounds strange. When you use the adaptor design pattern you have these participants. *Target -...
0
by: Tony Johansson | last post by:
Hello!! This is about the adaptor design pattern. If you use the class adaptor its easy to override. It says an object adaptor makes it harder to override Adaptee behavior. It will require...
4
by: Pushkar Pradhan | last post by:
I have some functions which take as i/p a buffer (it can be float, char, or 16 bit, int etc.). The result is another o/p buffer, its type is also flexible (it could be a float, char etc.). I try...
1
by: | last post by:
Greetings All, I'm trying to access a excel file using the odbc data adaptor but the tables arent showing up. I can get connected to the excel file using the Wizard but when I go to do the odbc...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.