fork download
  1. #include <algorithm> // algorithmic move
  2. #include <vector>
  3. #include <list>
  4. #include <iterator> // front_inserter
  5. #include <iostream>
  6.  
  7. int main(){
  8. std::vector<int> v;
  9. std::list<int> l;
  10.  
  11. v.reserve(10);
  12. for (unsigned i = 0; i < 10; ++i)
  13. v.push_back(i);
  14.  
  15. // I used 'rbegin' and 'rend' so the order stays the same
  16. std::move(v.rbegin(), v.rend(), std::front_inserter(l));
  17.  
  18. std::copy(l.begin(), l.end(), std::ostream_iterator<int>(std::cout, " "));
  19. }
Success #stdin #stdout 0s 3060KB
stdin
Standard input is empty
stdout
0 1 2 3 4 5 6 7 8 9