std:unique really just shifts items to the beginning as needed. The shift is not what you think. It should not be some kind of propagated singleton at that time. He can take advantage of the requirement by which an element must be assigned to move. By definition, move-assign, as soon as an element is moved, its previous contents are not specified. In your case, it just stores the โvalueโ there, but it is not the specified value.
In short, what you see is the remaining values, and some of them may be nonspecific.
Below is a simple demonstration of your data. Initially, we have two places in the slots, R and W. I do not place any orders, this is the algorithm used by std::unique (to be honest, I do not know).
By trimming the trivial case (0 or 1-length sequence) when the value is to be stored, it is assigned by wrapping in the next slot above W, and W advances. Regardless of whether it is stored or not, R is always advancing. When this is done, the slot W is the last (i.e., the first of the remaining slots, some of which may have undefined values).
Given your data, the sequence would be something like this:
1, 2, 2, 2, 3, 3, 2, 2, 1 - different, since the write target WR is the same as the read-point, do nothing, and advance both R and W 1, 2, 2, 2, 3, 3, 2, 2, 1 - equivalent, advance R only WR 1, 2, 2, 2, 3, 3, 2, 2, 1 - equivalent, advance R only WR 1, 2, 2, 2, 3, 3, 2, 2, 1 - different, move the 3 to the next write WR point and advance both R and W 1, 2, 3, 2, 3, 3, 2, 2, 1 - equivalent, advance R only WR 1, 2, 3, 2, 3, 3, 2, 2, 1 - different, move the 2 to the next write WR slot and advance both R and W 1, 2, 3, 2, 3, 3, 2, 2, 1 - equivalent, advance R only WR 1, 2, 3, 2, 3, 3, 2, 2, 1 - different, move the 1 to the next write WR slot and advance both R and W 1, 2, 3, 2, 1, 3, 2, 2, 1 - read is at end-of-sequence WR
At this point, the reader is done. the first interval after W is equal to last as the algorithm goes (and can really be end if the original sequence had no duplicates). I leave you the task of determining which elements (3,2,2,1) are in the โunspecifiedโ state after this.
Hint: what was moved? What was missed? What has been rewritten? Why does it matter? Try writing 0 to the slot for reading everything that has been moved, and see what is left in the sequence from last to end .