sort predicate

Imagine a class type Employee and the desire to sort by the member function number() which returns the Employee ID:

  class Employee
  {
  public:
     int number() const;
  };
  ...

  std::sort(v.begin(), v.end(),
     bind(std::less<int>(),
        bind(&Employee::number, _1),
        bind(&Employee::number, _2)
     )
  );  

The member function number is converted into a functor: once for the first argument, and once for the second argument to sort's compare predicate. Then those two bind expressions are composed as arguments to std::less<int>. Without bind you would have to write a custom binary compare predicate for this situation (or operator< for Employee).

Note that if you change Employee to:

  class Employee
  {
  public:
     int number;
  };  

then the predicate developed above for sorting does not change.