vendredi 24 mars 2017

Sort a container of objects, that might not have a comparison operator

I have the following question which I didn't totally understood:

Sort a container (ex. std::vector, std::list) of objects(ex. container : [1,7,3,10]). But you might not assume that the representation and internal structure of the objects within the container can be modified. In particular the objects might not have a comparison operator.

I thought of something like this:

sort(container.begin(), container.end(), 
    [](const container & a, const container & b) -> bool
{ 
    return a > b; 
});

But this assumes that they have a comparison operator. Is there something missing in the question?

Aucun commentaire:

Enregistrer un commentaire