Hi All,
I just read the book called "C++ coding stardards - 101 rules". And Found there is something I don't understand.
class FlagNth {
public:
FlagNth( size_t n ) : current_(0), n_(n) {}
// evaluate to true if and only if this is the n-th invocation
template<typename T>
bool operator()( const T& ) {return ++current_ == n_; } // bad: non-const
private:
size_t current_, n_;
};
// … later …
v.erase( remove_if( v.begin(), v.end(), FlagNth(3) ) );
According to the book, it said "This is not guaranteed to remove the third element, even though that was intended. In most real-world STL implementations, it erases both the third and the sixth elements."
But since remove_if return a forward iterator pointing to the new end of the sequence, why the code above only can remove the third element?
thanks