fork(1) download
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <vector>
  4.  
  5. int main() {
  6. const std::vector<double> v{1.5, 3.1, 12.88, 32.4};
  7.  
  8. const auto x = 13.0;
  9. auto it = std::adjacent_find(v.begin(), v.end(),
  10. [x](double lhs, double rhs){ return lhs <= x && x < rhs; });
  11. if (it != v.end()) {
  12. std::cout << *it << " " << *(it + 1) << std::endl;
  13. }
  14. }
  15.  
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
12.88 32.4