I need to sort a list of std::shared_ptr based on criteria defined via an overloaded operator < in the struct I'm storing via the smart pointers.
Naturally, the std::shared_ptr define operator < as
Code:
template<class _Ty1,
class _Ty2>
bool operator<(const shared_ptr<_Ty1>& _S1,
const shared_ptr<_Ty2>& _S2)
{ // test if shared_ptr < shared_ptr
return (_S1.get() < _S2.get());
}
That is, comparison of the pointers, while boost's smart pointer defines the operator via a comparison of the pointees.
So say I have
Code:
std::list<std::shared_ptr<my_t>> list;
// Add stuff to list
list.sort();
What would be a good approach to sort the list using the operator < defined in my_t?