Advertisement
ttldtor

Untitled

Dec 27th, 2012
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. #include <QVector>
  3. #include <QTextStream>
  4. #include <vector>
  5. #include <list>
  6. #include <deque>
  7.  
  8. struct MoveTest
  9. {
  10.     int i;
  11.  
  12.     MoveTest()                       {}
  13.     MoveTest(const MoveTest& other)  {QTextStream(stdout) << "constr copy" << endl;}
  14.     MoveTest(MoveTest &&other)       {QTextStream(stdout) << "constr move" << endl;}
  15.     ~MoveTest()                      {}
  16.  
  17.     inline MoveTest&    operator=   (const MoveTest& other) {QTextStream(stdout) << "copy" << endl;}
  18.     inline MoveTest&    operator=   (MoveTest &&other)      {QTextStream(stdout) << "move" << endl;}
  19. };
  20.  
  21. int main(int argc, char *argv[])
  22. {
  23.  
  24.     QTextStream(stdout) << "std::move:" << endl;
  25.     MoveTest t1;
  26.     MoveTest t2(std::move(t1));
  27.     t1 = std::move(t2);
  28.  
  29.     QTextStream(stdout) << "\nQVector:" << endl;
  30.     QVector<MoveTest> qmTest(5);
  31.     qmTest.insert(qmTest.begin(), MoveTest());
  32.  
  33.     QTextStream(stdout) << "\nstd::vector:" << endl;
  34.     std::vector<MoveTest> mTest(5);
  35.     mTest.emplace(mTest.begin());
  36.  
  37.     QTextStream(stdout) << "\nstd::list:" << endl;
  38.     std::list<MoveTest> mlTest(5);
  39.     mlTest.emplace(mlTest.begin());
  40.  
  41.     QTextStream(stdout) << "\nstd::deque:" << endl;
  42.     std::deque<MoveTest> mdTest(5);
  43.     mdTest.emplace(mdTest.begin(), MoveTest());
  44.     return 0;
  45. }
  46.  
  47.  
  48. ------------------------------------------------------------------
  49.  
  50. std::move:
  51. constr move
  52. move
  53.  
  54. QVector:
  55. constr copy
  56. constr copy
  57. constr copy
  58. constr copy
  59. constr copy
  60. constr copy
  61. copy
  62. copy
  63. copy
  64. copy
  65. copy
  66. copy
  67.  
  68. std::vector:
  69. constr copy
  70. constr copy
  71. constr copy
  72. constr copy
  73. constr copy
  74.  
  75. std::list:
  76.  
  77. std::deque:
  78. constr move
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement