vendredi 23 octobre 2020

Sorting objects vector with lambda, not sorting in the end

I'm trying to write a sort function for vectors using lambda, and I've seen this suggested at so many places, but I've always had problems doing this.

std::sort(eventvec.begin(), eventvec.end(), [](const event& lhs, const event& rhs) {
    return lhs.getim < rhs.getim;});

I had multiple errors while writing it and then I kind of stacked it on a function within a function as it needed a static function.

The functions declared in the class are:

double event::getut() { return unift; }

static double getim(event &a) { return a.getut(); }

In the end the sorting is not in order at all. There are negative values as well in the attribute. Any suggestions?

Aucun commentaire:

Enregistrer un commentaire