Comparison objects used in STL containers, as well as predicates used in STL algorithms, must be objects to be copied, and methods and algorithms can copy these functions, no matter how they wish.
This means that if the comparison object contains a state, this state must be copied correctly, so you may need to provide a suitable copy constructor and copy assignment operator.
If you want the comparison object to contain a variable state, the problem is more complicated, since any copies of the comparison object must share the mutable state. If you can save state as a separate object, then you can have comparison objects keep a pointer to this external state; if not, you will probably find that you need shared ownership of the shared state, so you might need something like tr1::shared_ptr to manage this.
source share