c++ - lower_bound of vector of pairs with lambda -
i want find std::lower_bound
of std::vector
of std::pair
's according second element lambda.
std::vector < std::pair <int, double> > vec; vec.resize(5); auto = std::lower_bound(vec.begin(), vec.end(), lambda); // lambda here?
you're missing argument here, std::lower_bound
takes begin , end iterator, value (this missed) , can take lambda.
#include <algorithm> #include <vector> int main() { typedef std::pair<int, double> mypair; // typedef shorten type name std::vector <mypair> vec(5); mypair low_val; // reference value (set want) auto = std::lower_bound(vec.begin(), vec.end(), low_val, [](mypair lhs, mypair rhs) -> bool { return lhs.second < rhs.second; }); }
reference page lower_bound here.
Comments
Post a Comment