Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2004-09-20 05:40:03


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. ;-)


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