Even const member functions may access mutable data members, non-const local static objects, non-const class staic objects. non-const objects at namespace scope, and non-const global objects.
find_if never called p, it called only a copy of p;
tmplate<typename FwdIterator, typename Predicate>
FwdIterator remove_if(FwdIterator begin, FwdIterator end, Predicate p) {
begin = find_if(begin, end, p);
if (begin == end) return begin;
else {
FwdIterator next = begin;
return remove_copy_if(++next, end, begin, p);
}
}
class Predicate:
public unary_function<Widget, bool> {
public:
Predicate() {}
bool operator()(const Widget&) const {
return ++timesCalled == 3;
}
private:
static size_t timesCalled = 0;
};