
From: przemyslaw.sliwa@uk.bnpparibas.com
<snip>
In order to sort the objects in the set I have to use the functor
struct lessThan : public std::binary_function, boost::shared_ptr, bool> { bool operator ()(const boost::shared_ptr &lhs, const boost::shared_ptr &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?
You could write one class that works for all types: struct indirectLessThan { template <typename PtrT> bool operator()(PtrT a, PtrT b) { return *a < *b; } }; And use it like this: typedef std::set<eventIntLimPtr, indirectLessThan> eventIntLimPtrSet; And you can re-use this indirectLessThan class in other situtations where you want to compare pointers (whether shared_ptr or raw pointers) by comparing the things they point to. Regards, Nate.