Boost logo

Boost Users :

Subject: Re: [Boost-users] using std::list<boost::weak_ptr<T> >
From: Peter Dimov (pdimov_at_[hidden])
Date: 2009-04-11 15:31:31


Mario Klebsch:

...

> So, I thought, I might use a std::list of boost::weak_ptr. But my compiler
> complains about std::list::remove():

...

> It seems, that the compiler does not find an operator== for the
> boost::weak_ptr.

weak_ptr has no operator==. You need to use remove_if instead of remove,
passing it one of:

bool eq( weak_ptr<Channel> const & p, weak_ptr<Channel> const & q )
{
    return p.lock() == q.lock();
}

bool eq2( weak_ptr<Channel> const & p, weak_ptr<Channel> const & q )
{
    return !(p < q) && !(q < p);
}

Which one is better depends on your specific use case. The first one
considers two weak_ptr instances to be equal when they point to the same
object. The second one considers two weak_ptr instances to be equal when
they are copies.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net