I tried using it to sort my list but it always gives me the two errors:
error C3867: 'HarvestManager::compare_byDistance': function call missing argument list; use '&HarvestManager::compare_byDistance' to create a pointer to member
error C2660: 'std::list<_Ty>::sort' : function does not take 1 arguments
with
[
_Ty=std::pair<BWAPI::Unit *,std::pair<BWAPI::Unit *,BWAPI::Unit *>>
]
Notice that in my first two print_if calls I pass a function as the predicate,
while in the last two I pass an object of a class that overloads operator ().
In fact, I can pass anything I want as the predicate, as
long as this -> if ( pred(array[i]) ) is valid C++ code.
This means that I can't pass a member function as the predicate,
because the above is not a valid way to call a member function.
The same reasoning applies to the std::list::sort function comparator.
If I wanted to make my comparator a member function, it should
be a member of std::pair< /* ... */ >, and I can't do that.
I guess I could make a specialization of std::pair to implement
operator < the way I want, but that would not be very wise...
[EDIT]
Oops... operator < is not a member function of std::pair.
Still, writing a specialization for it is not a good choice,
as you may want to have more than one comparators.
[/EDIT]
Anyway, I don't think it's a good idea for a comparator to be a member
function, even if I have the option to do it. These functors you mention
are useful in situations where you want to use for_each with a member
function. Also, as you said, what you pass in that case is still a functor, so,
technically speaking, you can't pass a member function as a comparator :P