fork download
  1. #include <iostream>
  2. #include <queue>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. class C {
  8. public:
  9. C() {cout<<"CTOR\n";}
  10. ~C() {cout<<"DTOR\n";}
  11. C(const C& c) { cout<<"COPY CTOR\n";};
  12. C(const C&& c) { cout<<"MOVE CTOR\n";};
  13.  
  14. };
  15.  
  16. int main() {
  17.  
  18. {
  19. queue<C> c;
  20. C cobj;
  21. //cout<<"pushing normally:\n";
  22. //c.push(cobj);
  23. cout<<"pushing with move\n";
  24. c.push(move(cobj)); // same output as line above
  25. cout<<"popping\n";
  26. c.pop();
  27. //c.pop();
  28. cout<<"end of scope\n";
  29. }
  30. //cin.get();
  31. }
Success #stdin #stdout 0s 3020KB
stdin
Standard input is empty
stdout
CTOR
pushing with move
MOVE CTOR
popping
DTOR
end of scope
DTOR