Questo è il codice dal codice della libreria standard C ++ remove. Perché la disuguaglianza è testata come if (!(*first == val))anziché if (*first != val)?
template <class ForwardIterator, class T>
ForwardIterator remove (ForwardIterator first, ForwardIterator last, const T& val)
{
ForwardIterator result = first;
while (first!=last) {
if (!(*first == val)) {
*result = *first;
++result;
}
++first;
}
return result;
}
operator==si prevede che vengano usati qui ...
constesempio nell'esempio nel mio commento precedente, ma ottieni il punto. (Troppo tardi per modificarlo)
EqualityComparableche Hurkyl ha menzionato nella sua risposta .
operator!=. Basta usare l'operator==implementazione:bool operator!=(const Foo& other) { return !(*this == other); }