Advertisement
ttldtor

Untitled

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