Boost logo

Boost Users :

From: Joao Abecasis (jpabecasis_at_[hidden])
Date: 2005-11-26 09:03:32


Hi!

Sumanth J.V wrote:
> Now my code compiles. However, I would like to change the default
> behavior of the comparison operator. From the boost documentation, "the
> operators <, >, <= and >= implement a lexicographical ordering". But I
> would like comparison to be based only on the second element of the
> tuple. Is there anyway this can be implemented?

To this end, you may supply a custom comparison operator to std::sort.

     struct my_compare_op
     {
         bool operator()(const Task& a, const Task& b) const
         {
             return boost::get<1>(a) < boost::get<1>(b);
         }
     };

and then,

     std::sort(ts.begin(), ts.end(), my_compare_op());

HTH,

João Abecasis


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net