fork download
  1. #include <algorithm>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. #define IDEONE_BROKEN_CXX11_SUPPORT
  7. #ifdef IDEONE_BROKEN_CXX11_SUPPORT
  8. template <typename T, size_t N> T* begin(T(&arr)[N]) { return arr; }
  9. template <typename T, size_t N> T* end (T(&arr)[N]) { return arr+N; }
  10. #endif
  11. unsigned char data[/*70*1000*1000*/] = {0,2,1,1,0,2,1,4,2,/*...*/};
  12. unsigned int offsets[/*10*1000*1000*/] = {0,1,2,4,6,7,8,/*...*/};
  13.  
  14. void do_something_for_data_index(unsigned int data_index)
  15. {
  16. cout << "visited: " << (int) data[data_index] << " (at index " << data_index << ")\n";
  17. }
  18.  
  19. void foo(size_t first_data_index, size_t high_data_index)
  20. {
  21. const auto low = lower_bound(begin(offsets), end(offsets), first_data_index);
  22. const auto high = upper_bound(low , end(offsets), high_data_index);
  23. for(auto offset_it = low; offset_it != high; ++offset_it)
  24. {
  25. do_something_for_data_index(*offset_it);
  26. }
  27. }
  28.  
  29. int main()
  30. {
  31. foo(1,4);
  32. }
  33.  
Success #stdin #stdout 0s 2928KB
stdin
Standard input is empty
stdout
visited: 2 (at index 1)
visited: 1 (at index 2)
visited: 0 (at index 4)