Boost logo

Boost Users :

Subject: Re: [Boost-users] shared_ptr and std::set::erase
From: Bill Somerville (bill_at_[hidden])
Date: 2008-10-09 10:58:12

Javier Jerónimo wrote:
> Hello,
> I have:
> std::set< boost::shared_ptr< A > > m_set;
> and when I try to do:
> m_set.erase( somesharedptr );
> the shared_ptr is not removed from the set. There is already a
> shared_ptr object pointing to the same A object inside the set.
> I think it's because the definition of "shared_ptr<>::operator<" and
> its use in std::set<>::erase.
> What's the correct way of using a shared_ptr inside a set?
You will need to provide a less than predicate to the std::set that
looks through the shared pointer to its pointee value. You need that
anyway if you want the set to be a set of pointee values rather than a
set of shared pointers.

The less than operator for shared_ptr compares the address of the
pointee, not its value.
> Thanks.

Bill Somerville

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at