Can member functions be used as comparator functions for STL algorithms?

if so, how does one go about doing it?
Yes, overload the necessary relational operators. For example, std::map and std::set use operator<().
so I pass in < to the algorithm?
e.g. sort ( iterator1, iterator2, < )?
I seem to have a compiler error
If you don't pass anything it will be taken for default


from http://www.cplusplus.com/reference/algorithm/sort/
1
2
template <class RandomAccessIterator>
  void sort ( RandomAccessIterator first, RandomAccessIterator last );

1
2
template <class RandomAccessIterator, class Compare>
  void sort ( RandomAccessIterator first, RandomAccessIterator last, Compare comp );


Sort elements in range
Sorts the elements in the range [first,last) into ascending order.

The elements are compared using operator< for the first version, and comp for the second.

Elements that would compare equal to each other are not guaranteed to keep their original relative order.
Topic archived. No new replies allowed.