From: Michael Rutman (moose_at_[hidden])
Date: 2004-09-20 23:33:40
At 1:40 PM +0300 9/20/04, Peter Dimov wrote:
>Michael Rutman wrote:
>> I'd like to propose adding a template function to shared_ptr to allow
>> the automatic testing of a shared_ptr to its raw ptr.
>> The template is as simple as
>> template <class T>
>> bool operator==(boost::shared_ptr<T> const & a, T * const & b)
>> return a.get() == b;
>> 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 );
>This is a reasonable suggestion. It turns out that std::find _is_ specified
>in a way that allows heterogeneous comparisons, although this may be an
>oversight on the part of the committee and not a design decision. ;-)
I just found out that on gcc 2.96 it also needs the following
template <class T>
bool operator!=(boost::shared_ptr<T> const & a, T * const & b)
return a.get() != b;
gcc 3.3 works fine without this template but the earlier gcc needs both.
I'm not sure how that effects the proposal.
I see that you are the maintainer of shared_ptr. Is there any chance
you'll add this for the next release of boost?
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk