fork(1) download
  1. #include <vector>
  2. #include <iostream>
  3.  
  4. template <typename T>
  5. void foo(T begin, T end)
  6. {
  7. for (; begin != end; ++begin)
  8. {
  9. std::cout << " " << *begin;
  10. }
  11. }
  12.  
  13. template <typename T>
  14. void foo(T begin, std::reverse_iterator<T> end)
  15. {
  16. foo(begin, end.base());
  17. }
  18.  
  19. template <typename T>
  20. void foo(std::reverse_iterator<T> begin, T end)
  21. {
  22. foo(begin, std::reverse_iterator<T>(end));
  23. }
  24.  
  25. int main()
  26. {
  27. std::vector<int> v { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
  28. foo(v.begin(), v.end()); std::cout << std::endl;
  29. foo(v.begin(), v.rbegin()); std::cout << std::endl;
  30. foo(v.rbegin(), v.begin()); std::cout << std::endl;
  31. foo(v.rbegin(), v.rend()); std::cout << std::endl;
  32. }
  33.  
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
 1 2 3 4 5 6 7 8 9
 1 2 3 4 5 6 7 8 9
 9 8 7 6 5 4 3 2 1
 9 8 7 6 5 4 3 2 1