title: C++ std::queue pop() and destructor
body: <p>I originally thought when a queue is destructed (e.g. when it goes out of scope), then the contained elements should be destructed (by calling their respective destructor). Similarly, when pop() is called, the first element in the queue is destructed and the queue's size is reduced by 1. </p>
  
  <p>However, when I verified my understanding, it seems incorrect... I used something like this</p>
  
  <pre><code>string&amp; str = myQueue.front();
  myQueue.pop();
  </code></pre>
  
  <p>(where myQueue is a non-empty queue containing strings).</p>
  
  <p>According to <code>front()</code> spec, it should return a reference to the first element it holds, <a href="http://www.cplusplus.com/reference/queue/queue/front/" rel="nofollow">as seen here</a>.</p>
  
  <p>This means, when I pop the queue, the first element is gone. It turns out "str" is still a valid string afterwards!</p>
  
  <p>Is there something wrong?</p>
  
  <p>Thanks!</p>