unique(), unique_copy()
All consecutive groups of elements containing either the same value (using the equality operator) or evaluating as true when passed an optional alternative comparison operation are collapsed into a single element. In the word Mississippi, the semantic result is “Misisipi.” Because the three i’s are not consecutive, they are not collapsed, nor are the two pairs of s’s. To guarantee that all duplicated elements are collapsed, we would first sort the container.
As with remove(), the container’s actual size is not changed. Each unique element is assigned in turn to the next free slot, beginning with the first element of the container. In our example, the physical result is “Misisipippi,” where the character sequence ppi ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access