转自overstackflow
Two things:
-
Define your
bool operator()
asconst
. It's just a good practice. This tells the compiler that this function will not have side-effects on the member variables of the class. -
Add
const &
qualifiers to thelhs
andrhs
arguments. Passing constant references instead of copying memory all over the place is also good practice. By declaring references asconst
you're telling compiler that this function should not have side-effects on the referenced objects.
Your operator()
should
look as follows:
bool operator() (const string &lhs, const string &rhs) const
{
return strcasecmp(lhs.c_str(), rhs.c_str()) < 0;
}