title: Understanding move constructor, std::move, and destructor
body: <p>I am new to c++11 and wrote the following code to understand how <code>std::move</code> works:</p>
  
  <pre><code>#include &lt;queue&gt;
  #include &lt;stdio.h&gt;
  
  class X {
   public:
    X(int x) : x_(x) {}
    ~X() {
      printf("X(%d) has be released.\n", x_);
    }
  
    X(X&amp;&amp;) = default;
    X&amp; operator = (X&amp;&amp;) = default;
  
    X(const X&amp;) = delete;
    X&amp; operator = (const X&amp;) = delete;
   private:
    int x_;
  };
  
  
  int main() {
    std::queue&lt;X&gt; xqueue;
    for (int x = 0; x &lt; 5; ++x) {
      xqueue.push(std::move(X(x)));
    }
    return 0;
  }
  </code></pre>
  
  <p>However, it generates the following output, which indicates that the destructor of each <code>X(n)</code> has been called twice:</p>
  
  <pre><code>X(0) has be released.
  X(1) has be released.
  X(2) has be released.
  X(3) has be released.
  X(4) has be released.
  X(0) has be released.
  X(1) has be released.
  X(2) has be released.
  X(3) has be released.
  X(4) has be released.
  </code></pre>
  
  <p>I can imagine the second round of the output happens right at the end of <code>main()</code> function, and the first round probably happens in the loop when those intermediate <code>X</code>s ran out of scope.</p>
  
  <p>But, I thought the ownership of such intermediate <code>X</code>s will be perfectly transferred into the queue and their destructors should not be called during their ownership transfer.</p>
  
  <p>So my questions are:</p>
  
  <ol>
  <li>When I saw an instance being deallocated twice, does that mean it performs copy instead of move?</li>
  <li>If the above answer is yes, then how can I really avoid copying?</li>
  </ol>
  
  <p>Thank you,</p>