C++ does list.unique() resize the list?

Go To StackoverFlow.com


Does a call of unique() on a list also resize the list if repeats are found?

2012-04-04 05:32
by user788171
... as opposed to std::unique, I suppose - visitor 2012-04-04 09:02


Yes, it does. It removes the duplicate elements. So the size of the list changes as well.

Have a look at the documentation here. It says:

The elements removed have their destructors called and their iterators and references become invalid.

Note that in case of std::list, while erasing an element, only the iterators and references to the erased element are invalidated [].

2012-04-04 05:35
by Alok Save