Boost logo

Boost :

From: Michael Rutman (moose_at_[hidden])
Date: 2004-09-17 11:26:10


At 12:06 PM +0200 9/17/04, Vukasin Toroman wrote:
>On Thursday 16 September 2004 22:34, Michael Rutman wrote:
>> Here is the case where I need it.
>>
>> I have a vector<Foo> myFoo.
>>
>> In a method of Foo I need to see if this instance is in the vector. I want
>> to do this
>>
>> vector<Foo>::iterator iter = find( myFoo.begin(), myFoo.end(), this );
>
>wouldn't it be better to simply specify a compare functor for your container?

I do not believe so. By that logic a compare functor would have been
better than all the other template comparisons already approved.

Just as I want to be able to type safely compare two shared_ptr's of
different types (subclasses for example) I want to type safely compare the
shared_ptr to the raw pointer.

As an aside, this came about because the initial reaction was to do the
following, which is REALLY bad

vector<Foo>::iterator iter = find( myFoo.begin(), myFoo.end(),
shard_ptr(this) );

It compiles just fine, then quickly crashes when it leaves scope and
deletes this.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk