fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5.  
  6. struct Thing {
  7. Thing() {}
  8. //Thing(Thing &&) { std::cout << "Moved a thing" << std::endl; }
  9. Thing & operator=(Thing &&) { std::cout << "Moved a thing" << std::endl; }
  10. };
  11.  
  12.  
  13. int main() {
  14. std::vector<Thing> source1(1);
  15. std::vector<Thing> source2(1);
  16.  
  17. std::cout << "Move vector:" << std::endl;
  18. std::vector<Thing> vector_moved{std::move(source1)};
  19.  
  20. std::cout << "-------------" << std::endl;
  21.  
  22. std::cout << "Move elements:" << std::endl;
  23. std::vector<Thing> elements_moved{source2.size()};
  24. std::move_backward(source2.begin() , source2.end(), elements_moved.end());
  25.  
  26. return 0;
  27. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
Move vector:
-------------
Move elements:
Moved a thing