Note that there are some explanatory texts on larger screens.

plurals
  1. POInternal moving std::vector elements and QVector
    primarykey
    data
    text
    <p>There are two vectors <code>std :: vector</code> and <code>QVector</code>. We have to check how "shift" elements when inserted. (Is constructed two vectors with the five elements and inserted zero element) I've this code:</p> <pre><code>#include &lt;QVector&gt; #include &lt;QTextStream&gt; struct MoveTest { int i; MoveTest() {} MoveTest(const MoveTest&amp; other) {QTextStream(stdout) &lt;&lt; "constr copy" &lt;&lt; endl;} MoveTest(MoveTest &amp;&amp;other) {QTextStream(stdout) &lt;&lt; "constr move" &lt;&lt; endl;} ~MoveTest() {} inline MoveTest&amp; operator= (const MoveTest&amp; other) {QTextStream(stdout) &lt;&lt; "copy" &lt;&lt; endl;} inline MoveTest&amp; operator= (MoveTest &amp;&amp;other) {QTextStream(stdout) &lt;&lt; "move" &lt;&lt; endl;} }; int main(int argc, char *argv[]) { QTextStream(stdout) &lt;&lt; "std::move:" &lt;&lt; endl; MoveTest t1; MoveTest t2(std::move(t1)); t1 = std::move(t2); QTextStream(stdout) &lt;&lt; "QVector:" &lt;&lt; endl; QVector&lt;MoveTest&gt; qmTest(5); qmTest.insert(qmTest.begin(), MoveTest()); QTextStream(stdout) &lt;&lt; "std::vector:" &lt;&lt; endl; std::vector&lt;MoveTest&gt; mTest(5); mTest.insert(mTest.begin(), MoveTest()); return 0; } </code></pre> <p>My output with gcc 4.7.2, QMAKE_CXXFLAGS += -std=c++0x:</p> <pre><code>std::move: constr move move QVector: constr copy constr copy constr copy constr copy constr copy constr copy copy copy copy copy copy copy std::vector: constr move constr copy constr copy constr copy constr copy constr copy </code></pre> <p>How to insert elements with an internal shift without copying? What GCC flags are needed?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload