...
- implement a function call operator that does not mutate state related to the function object's identity, such as nonstatic data members or captured values, or,
- wrap the predicate function object in a
std::reference_wrapper<T>
(or an equivalent solution).
Note that marking the function call operator as const
is beneficial, but insufficient because data members with the mutable
storage class specifier may still be modified within a const
member function.
Noncompliant Code Example (Functor)
...
This program produces the following results, using gcc 4.8.1 with libstdc++:
Contains: 0 1 2 3 4 5 6 7 8 9
Contains: 0 1 3 4 6 7 8 9
...