fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using std::cout;
  5. using std::endl;
  6. using std::vector;
  7.  
  8. #define V(p) static_cast<void const*>(p)
  9.  
  10. struct Thing {
  11. Thing() {}
  12. Thing(Thing const & t) {
  13. cout << "Copy " << V(&t) << " to " << V(this) << endl;
  14. }
  15. Thing(Thing && t) noexcept {
  16. cout << "Move " << V(&t) << " to " << V(this) << endl;
  17. }
  18. };
  19.  
  20. int main() {
  21. vector<Thing> things;
  22. for (int i = 0; i < 10; ++i) {
  23. cout << "Have " << things.size() << " (capacity " << things.capacity()
  24. << "), adding another:\n";
  25. things.emplace_back();
  26. }
  27. }
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
Have 0 (capacity 0), adding another:
Have 1 (capacity 1), adding another:
Move 0x2b652d9ccc30 to 0x2b652d9ccc50
Have 2 (capacity 2), adding another:
Move 0x2b652d9ccc50 to 0x2b652d9ccc30
Move 0x2b652d9ccc51 to 0x2b652d9ccc31
Have 3 (capacity 4), adding another:
Have 4 (capacity 4), adding another:
Move 0x2b652d9ccc30 to 0x2b652d9ccc50
Move 0x2b652d9ccc31 to 0x2b652d9ccc51
Move 0x2b652d9ccc32 to 0x2b652d9ccc52
Move 0x2b652d9ccc33 to 0x2b652d9ccc53
Have 5 (capacity 8), adding another:
Have 6 (capacity 8), adding another:
Have 7 (capacity 8), adding another:
Have 8 (capacity 8), adding another:
Move 0x2b652d9ccc50 to 0x2b652d9ccc30
Move 0x2b652d9ccc51 to 0x2b652d9ccc31
Move 0x2b652d9ccc52 to 0x2b652d9ccc32
Move 0x2b652d9ccc53 to 0x2b652d9ccc33
Move 0x2b652d9ccc54 to 0x2b652d9ccc34
Move 0x2b652d9ccc55 to 0x2b652d9ccc35
Move 0x2b652d9ccc56 to 0x2b652d9ccc36
Move 0x2b652d9ccc57 to 0x2b652d9ccc37
Have 9 (capacity 16), adding another: