I have a
class Widget;
std::list<Widget*> listOfPointers;
where the listOfPointers
may contain two or more pointers pointing to the same object. All pointers are pointing to objects which are created one by one on the heap and are not members of the same array.
How can I get rid of the duplicates?
I tried:
listOfPointers.sort();
listOfPointers.unique();
but this is undefined behavior since operator < is not defined for pointers in my problem.
I can compare each pointer to each other using the defined operator==, but this would lead to quadratic complexity.