Sorting a container of shared_ptr<T>
Hello to everyone. I'm starting to take a look on Boost and was happy to find things like better smart pointers. Though, in my tests, I haven't been able to sort, say, a vector of shared_ptr without defining special comparators. I thought that the overload for the < operator would help me for that, but that operator compares pointers, not objects, so it doesn't do the work that I expected. I guess I'm not understanding this well. Could someone explain this to me? Saludos, Alex
On Thursday, August 29, 2002, at 11:07 AM, alejandro_escalante_medina wrote:
Hello to everyone. I'm starting to take a look on Boost and was happy to find things like better smart pointers. Though, in my tests, I haven't been able to sort, say, a vector of shared_ptr without defining special comparators. I thought that the overload for the < operator would help me for that, but that operator compares pointers, not objects, so it doesn't do the work that I expected.
I guess I'm not understanding this well. Could someone explain this to me?
Almost any technique that works for sorting a container of pointers, based on the values of the objects pointed to would also work for a container of shared_ptr's. That's the design approach of shared_ptr; it has the same semantics as pointers. I found an article by Dietmar Kuehl at http://www.oonumerics.org/tmpw00/kuehl.html which talks about this very issue. You might find it helpful. -- Darin
participants (2)
-
alejandro_escalante_medina
-
Darin Adler