vendredi 6 juillet 2018

Explain the working of compare predicate of standard library sort function C++?

After reading some answers on stackoverflow I still couldn't understand when will compare function has to return false and when will it return true. In this answer it is written that it models the less than operator but still what I think now is that if compare function is like:

bool compare(const myClass& object1, const myClass& object2)
{
     if(object1.property < object2.property)
         return true;
     else
         return false;
}

will sort a vector of myclass objects in ascending order. Am I right?...I think I'm still confused.

Aucun commentaire:

Enregistrer un commentaire