fork download
  1. #include <iostream>
  2. #include <map>
  3. #include <tuple>
  4. using namespace std;
  5.  
  6. int main() {
  7.  
  8. std::map<int, std::map<int,int>> m{
  9. { 1, { { 1, 11}, { 2, 12} } },
  10. { 2, { { 2, 22}, { 4, 24} } },
  11. { 3, { { 5, 35} } }
  12. };
  13.  
  14. cout << "Less simple search: "<<std::endl;
  15. auto r1 = m.find (1);
  16. if (r1!=m.end()) {
  17. auto r12 = r1->second.find(2);
  18. if (r12!=r1->second.end())
  19. std::cout<<"Found r1 -> "<< r12->second << std::endl;
  20. else std::cout<<"second component for r1 not found"<<std::endl;
  21. }
  22. else std::cout<<"r1 not found !"<<std::endl;
  23.  
  24. cout << "Flexibilized range search: "<<std::endl;
  25. int x=2;
  26. auto r3 = m.find (x);
  27. if (r3==m.end())
  28. std::cout<<"r3 not found"<<std::endl;
  29. else for (auto r : r3->second) {
  30. std::cout<<"In range -> "<< r.second << std::endl;
  31. }
  32.  
  33. return 0;
  34. }
Success #stdin #stdout 0s 4284KB
stdin
Standard input is empty
stdout
Less simple search: 
Found r1 -> 12
Flexibilized range search: 
In range -> 22
In range -> 24