Removing duplicate values from std::list
I have an std::list<BallPair> list, where BallPair is a custom class that overloads operator==. In the list there are duplicate values, which I want to remove. I tried the following:
typedef std::list<BallPair>::iterator BallPairListItor;
but unfortunately list iterators do not provide operator + or operator -.
for(BallPairListItor i = l.begin(); i != l.end(); ++i)
for(BallPairListItor j = l.begin() + 1; j != l.end() - 1; ++j)
if(*i == *j)
j = l.erase(j);
I also tried list::unique but at unique - C++ Reference says:
Notice that an element is only removed from the list if it is equal to the element immediately preceding it.