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?
return lhs.getim() < rhs.getim();instead of what you wrote.return lhs.getut() < rhs.getut()but that means you need to makegetut()const. Like this:double event::getut() const { return unift; }double event::getut() const { return unift; }"