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

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -