fork(4) download
  1. #include <iostream>
  2. #include <map>
  3.  
  4. #include <boost/optional.hpp>
  5.  
  6. int main()
  7. {
  8. const std::map<int, boost::optional<double>> distanceToIdMap =
  9. {
  10. {0, boost::none},
  11. {100, 8.4},
  12. {200, 7.2},
  13. {300, 3.6},
  14. {400, boost::none},
  15. {600, 4.1}
  16. };
  17.  
  18. for (auto v : {-10, 50, 99, 100, 101, 250, 350, 500, 601})
  19. {
  20. auto it = distanceToIdMap.lower_bound(v);
  21.  
  22. if (it != distanceToIdMap.end() && it->second) {
  23. std::cout << v << " " << *it->second << std::endl;
  24. } else {
  25. std::cout << v << " None" << std::endl;
  26. }
  27. }
  28. }
Success #stdin #stdout 0s 3276KB
stdin
Standard input is empty
stdout
-10 None
50 8.4
99 8.4
100 8.4
101 7.2
250 3.6
350 None
500 4.1
601 None