The behavior of this function template is equivalent to:
1 2 3 4 5 6 7 8 9 10 11
template <class ForwardIterator>
ForwardIterator unique ( ForwardIterator first, ForwardIterator last )
{
ForwardIterator result=first;
while (++first != last)
{
if (!(*result == *first)) // or: if (!pred(*result,*first)) for the pred version
*(++result)=*first;
}
return ++result;
}
Am I missing something here,seems that *(++result)=*first; is trying to assign the *first to *first which are the same ?
Then every assignment would require an additional comparison for equality, while as a result, you only save assignments if there's a large number of unique values at the beginning of the range.