(C++) std::lower\_bound
January 11, 2018 · View on GitHub
(C++) std::lower_bound
std::lower_bound is an STL algorithm to find an element in a container smaller than a certain value.
#include <algorithm> #include <cassert> #include <vector> int main() { std::vector<int> v; v.push_back(1); v.push_back(2); v.push_back(3); //Lower bound will point to first element not smaller than 2 assert(*std::lower_bound(v.begin(),v.end(),2)==2); //Upper bound will point to first element larger than 2 assert(*std::upper_bound(v.begin(),v.end(),2)==3); }