Boost logo

Boost Users :

Subject: [Boost-users] Using boost::shared_ptr with std::set
From: przemyslaw.sliwa_at_[hidden]
Date: 2011-04-04 10:48:21


I have to use a set of shared pointers to objects. The struct I have to
use looks like

        struct eventIntLim
                enum eType { eStart = 0, eEnd };

                eType type;
                double varianceBump;

                eventIntLim(eType t, double v) : type(t), varianceBump(v)

                bool operator < (const eventIntLim &rhs) const
                        return fabs(varianceBump) <

and the definition of the set is

                typedef boost::shared_ptr<eventIntLim> eventIntLimPtr;
                typedef std::set<eventIntLimPtr, lessThan>
                typedef std::map<size_t, eventIntLimPtrSet>

In order to sort the objects in the set I have to use the functor

        struct lessThan : public
boost::shared_ptr<eventIntLim>, bool>
                bool operator ()(const boost::shared_ptr<eventIntLim>
&lhs, const boost::shared_ptr<eventIntLim> &rhs) const
                        return (*lhs) < (*rhs);

This is quite long and I believe boost can shorten it a lot. I have tried
it with boost::lamba and boost::bind but could not make it working.
Basically I would like to eliminate the need of writing the definition of
struct lessThan. Could someone help me with that?


This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and delete this e-mail. Any unauthorised copying, disclosure or distribution of the material in this e-mail is prohibited.

Please refer to for additional disclosures.

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