fork download
  1. #include <algorithm>
  2. #include <vector>
  3. #include <iostream>
  4.  
  5. int main ( )
  6. {
  7. auto compare_first = [](std::pair<int, int> const & a, std::pair<int, int> const & b){
  8. return a.first < b.first;
  9. };
  10.  
  11. auto compare_second = [](std::pair<int, int> const & a, std::pair<int, int> const & b){
  12. return a.second < b.second;
  13. };
  14.  
  15. std::vector<std::pair<int, int>> values { {2,3}, {2,4}, {3,2}, {3,4}, {3,5} };
  16.  
  17. std::pair<int, int> value { 2, 3 };
  18.  
  19. auto it_c = std::upper_bound(values.begin(), values.end(), value, compare_first);
  20. auto it = std::upper_bound(it_c, values.end(), value, compare_second);
  21.  
  22. std::cout << it->first << ',' << it->second;
  23. }
Success #stdin #stdout 0s 4320KB
stdin
Standard input is empty
stdout
3,4