|
Boost Users : |
Subject: [Boost-users] Using boost::shared_ptr with std::set
From: przemyslaw.sliwa_at_[hidden]
Date: 2011-04-04 10:48:21
Hello,
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) <
fabs(rhs.varianceBump);
}
};
and the definition of the set is
typedef boost::shared_ptr<eventIntLim> eventIntLimPtr;
typedef std::set<eventIntLimPtr, lessThan>
eventIntLimPtrSet;
typedef std::map<size_t, eventIntLimPtrSet>
eventIntLimMap;
In order to sort the objects in the set I have to use the functor
struct lessThan : public
std::binary_function<boost::shared_ptr<eventIntLim>,
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?
Cheers
___________________________________________________________
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 http://www.bnpparibas.co.uk/en/information/legal_information.asp?Code=ECAS-845C5H for additional disclosures.
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