fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. struct test{
  6. test(){ cout << "ctor" << endl;}
  7. test(const test&) { cout << "copy" << endl; }
  8. test(test&&) { cout << "move" << endl; }
  9. ~test(){ cout << "dtor" << endl;}
  10.  
  11. test& operator=(const test&) { cout << "assignment" << endl; return *this; }
  12. test& operator=(test&&) {cout << "move assignment" << endl; return *this; }
  13. };
  14.  
  15. int main() {
  16. cout << "Construction" << endl;
  17.  
  18. basic_string<test> foo;
  19.  
  20. cout << "resize(3)" << endl;
  21. foo.resize(3);
  22. cout << "resize(1)" << endl;
  23. foo.resize(1);
  24. cout << "Destruction" << endl;
  25. return 0;
  26. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
ctor
Construction
resize(3)
ctor
copy
assignment
copy
copy
assignment
assignment
assignment
dtor
dtor
assignment
dtor
dtor
resize(1)
ctor
assignment
dtor
Destruction
dtor