fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. template<class T>
  7. class ReversedProxy {
  8. public:
  9. using iterator = typename T::reverse_iterator;
  10. iterator begin() { return begin_; }
  11. iterator end() { return end_; }
  12. ReversedProxy(const iterator& begin, const iterator& end) : begin_(begin), end_(end) {}
  13. private:
  14. iterator begin_;
  15. iterator end_;
  16. };
  17. template<class T>
  18. ReversedProxy<T> reversed(T& obj) {
  19. return ReversedProxy<T>(obj.rbegin(), obj.rend());
  20. }
  21.  
  22. int main() {
  23. vector<int> v = {1, 2, 3, 4};
  24. for (int x : reversed(v)) {
  25. cout << x << ' ';
  26. } cout << endl;
  27. return 0;
  28. }
  29.  
  30.  
  31.  
  32.  
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
4 3 2 1