fork(2) download
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <utility>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9. const vector<pair<int, int>> intervals = { { 1, 3 },{ 7, 9 },{ 13, 13 } };
  10. std::vector<double> values = { 4.2, 6.4, 2.3, 3.4, 9.1, 2.3, 0.6, 1.2, 0.3, 0.4, 6.4, 3.6, 1.4, 2.5, 7.5 };
  11. size_t write = 0U;
  12. auto it = cbegin(intervals);
  13.  
  14. values.resize(distance(begin(values), remove_if(begin(values), end(values), [i = 0U, it = cbegin(intervals), end = cend(intervals)](const auto&) mutable { return it != end && ++i > it->first && (i <= it->second || (++it, true)); })));
  15. /*for (size_t read = 0U; read < size(values); ++read) {
  16. if (it == cend(intervals) || read < it->first) {
  17. values[write++] = values[read];
  18. } else if (read == it->second) {
  19. ++it;
  20. }
  21. }
  22.  
  23. values.resize(write);*/
  24.  
  25. for (const auto& i : values) cout << i << ' ';
  26. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
4.2 2.3 0.6 1.2 0.3 1.4 2.5 7.5