[smart_ptr] Easing the use of smart_ptr in case sorting is required

Hello everybody, Often , when someone creates a collection of smart_ptr, he wants the collection to be sorted by objects, and not by pointer adresses (this is what is used for instance in ptr_containers). To do that, one can provide his functor to the container/algorithm required, but this is burdensome. I do not think that modifying the current behaviour of smart pointers to make the comparison of smart pointers compare objet would be a good idea (even in cases it is possible to compare by objects, people who do not need this sorting would be impacted by the performances of sorting by objects). However, since this a quite a common thing to do, I wonder wether such a functor could be provided inside the smart_ptr headers, so that people who want to use this option can use it directly. What are your feelings about this idea ? Best regards, -- Loïc

"Loïc Joly" <loic.actarus.joly@numericable.fr> wrote in message news:4328907E.8050606@numericable.fr...
Hello everybody,
Often , when someone creates a collection of smart_ptr, he wants the collection to be sorted by objects, and not by pointer adresses (this is what is used for instance in ptr_containers). To do that, one can provide his functor to the container/algorithm required, but this is burdensome.
I do not think that modifying the current behaviour of smart pointers to make the comparison of smart pointers compare objet would be a good idea (even in cases it is possible to compare by objects, people who do not need this sorting would be impacted by the performances of sorting by objects). However, since this a quite a common thing to do, I wonder wether such a functor could be provided inside the smart_ptr headers, so that people who want to use this option can use it directly.
This functionality is already available in <boost/utility/compare_pointees.hpp>. There are two functions, equal_pointees() and less_pointees(), and two corresponding classes, equal_pointees_t and less_pointees_t. Joe Gottman

Joe Gottman a écrit :
This functionality is already available in <boost/utility/compare_pointees.hpp>. There are two functions, equal_pointees() and less_pointees(), and two corresponding classes, equal_pointees_t and less_pointees_t.
Oh, I was'nt aware of that ! Thank you for the information. Regards, -- Loïc

This functionality is already available in <boost/utility/compare_pointees.hpp>. There are two functions, equal_pointees() and less_pointees(), and two corresponding classes, equal_pointees_t and less_pointees_t.
Oh, I was'nt aware of that ! Thank you for the information.
I've come across this need before as well, and I rolled my own because I wasn't aware of its preexistence either. Searching for now I know what its called only yielded several source files, and one reference to it in the optional docs. Perhaps it should be documented in the utility library, or the smart_ptr library? Sam

Sam Partington <sam.partington <at> gmail.com> writes:
This functionality is already available in <boost/utility/compare_pointees.hpp>. There are two functions, equal_pointees() and less_pointees(), and two corresponding classes, equal_pointees_t and less_pointees_t.
Perhaps it should be documented in the utility library, or the smart_ptr library?
http://www.boost.org/libs/ptr_container/doc/indirect_fun.html might be useful too. br -Thorsten
participants (4)
-
Joe Gottman
-
Loïc Joly
-
Sam Partington
-
Thorsten Ottosen