Brief introduction
As the name suggests, unique, unique. This function can be "de-emphasis" in the container elements.
Note, however, where the "go heavy" and did not delete the duplicate elements, but does not duplicate elements brought to the front .
- First argument is the address of the first element of the container; the second argument is the address of the end of the container element
Return value of the function is the end address of the "de-emphasis"
unique () can only be used in an ordered sequence
Specific use
Simple and practical
vector<int> v;
v.push_back(1), v.push_back(1), v.push_back(2), v.push_back(3);
int pos = unique(v.begin(), v.end()) - v.begin();
cout << pos << endl; // 3
With vector.erase () to achieve real weight
vector<int> v;
v.push_back(1), v.push_back(1), v.push_back(2), v.push_back(3);
v.erase(unique(v.begin(), v.end(), v.end()));