fork download
  1. #include <iostream>
  2. #include <iterator>
  3. #include <algorithm>
  4. #include <vector>
  5. #include <cassert>
  6.  
  7.  
  8. template<typename C>
  9. C operator ~(C c) {
  10. assert(!c.empty());
  11. typename C::iterator b = c.begin();
  12. std::rotate(c.begin(), ++b, c.end());
  13. return c;
  14. }
  15.  
  16.  
  17. int main() {
  18. std::vector<int> v;
  19.  
  20. v.push_back(2);
  21. v.push_back(4);
  22. v.push_back(7);
  23.  
  24. std::copy(v.begin(), v.end(), std::ostream_iterator<int>(std::cout, " "));
  25. std::cout << std::endl;
  26.  
  27. v = ~v;
  28.  
  29. std::copy(v.begin(), v.end(), std::ostream_iterator<int>(std::cout, " "));
  30. std::cout << std::endl;
  31. }
  32.  
Success #stdin #stdout 0s 3032KB
stdin
Standard input is empty
stdout
2 4 7 
4 7 2