fork download
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <map>
  4. #include <tuple>
  5.  
  6. int main() {
  7. std::map<std::pair<int, int>, int> m { { {1,3}, 4 }, { {6, 10}, 5 }, { {123, 126}, 111 } };
  8. int x = 8;
  9.  
  10. auto result = std::find_if(std::begin(m), std::end(m), [x](const auto& v) {
  11. return v.first.first <= x && x <= v.first.second;
  12. });
  13.  
  14. if(result != std::end(m)) {
  15. std::cout << "FOUND x " << result->second;
  16. }
  17.  
  18. return 0;
  19. }
  20.  
Success #stdin #stdout 0s 4260KB
stdin
Standard input is empty
stdout
FOUND x 5