C++ lambdas for std::sort and std::lower_bound/equal_range on a struct element in a sorted vector of structs

前端 未结 5 794
旧时难觅i
旧时难觅i 2020-12-16 18:10

I have a std::vector of this struct:

struct MS
{        
  double aT;
  double bT;
  double cT;
};

which I want to use std::sort on aswell

5条回答
  •  心在旅途
    2020-12-16 18:53

    The algorithms std::sort, std::lower_bound, and std::binary_search take a predicate that compares two elements of the container. Any lambda that compares two MS objects and returns true when they are in order should work for all three algorithms.

提交回复
热议问题