fork(3) download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. #define METHOD(NAME, ...) auto NAME __VA_ARGS__ -> decltype(m_T.r##NAME) { return m_T.r##NAME; }
  6. template<typename T>
  7. struct Reverse
  8. {
  9. T& m_T;
  10.  
  11. METHOD(begin());
  12. METHOD(end());
  13. METHOD(begin(), const);
  14. METHOD(end(), const);
  15. };
  16. #undef METHOD
  17.  
  18. template<typename T>
  19. Reverse<T> MakeReverse (T& t) { return Reverse<T>{t}; }
  20.  
  21. int main ()
  22. {
  23. vector<int> v = {0, 1, 2, 3, 4, 5};
  24.  
  25. cout << "\nForward: ";
  26. for(auto& i : v)
  27. cout << i << ", ";
  28.  
  29. cout << "\nReverse: ";
  30. for(auto& i : MakeReverse(v))
  31. cout << i << ", ";
  32. }
  33.  
Success #stdin #stdout 0s 3228KB
stdin
Standard input is empty
stdout
Forward: 0, 1, 2, 3, 4, 5, 
Reverse: 5, 4, 3, 2, 1, 0,