Boost logo

Boost Users :

Subject: Re: [Boost-users] shared_ptr to object in stl set container?
From: Igor R (boost.lists_at_[hidden])
Date: 2011-12-13 05:07:59


> -- I'm trying to use shared_ptr in a stl set, but am having trouble with find()
>   Any help?  Documentation on this seems hard to find.
>
> -- Also, are the overloaded < and == useful or correct here?

No, std algorithms won't call your comparison operators, because those
of boost::shared_ptr do not compare pointees.
You can define in your cpp something like this (operator ==() is not
needed for your particular case):
namespace boost
{
        template<class T>
        bool operator <(const shared_ptr<T> &lhs, const shared_ptr<T> &rhs)
        {
                if (!lhs && !rhs)
                        return false;
                return *lhs < *rhs;
        }
}

Then move your operator <() out of Node class, and your programm will work.


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