Get container behind std::stack
<p>I am using a <code>std::stack</code> to keep a list of possibilities in my program.</p>

<pre><code>std::stack&lt;int, std::deque&lt;int&gt; &gt; myStack;
</code></pre>

<p>Now, for <strong>debugging purposes</strong> only, I want to have access to all the elements of my <code>std::stack</code> (for instance as a <code>std::deque</code>). But the following syntax is illegal:</p>

<pre><code>std::deque&lt;int&gt; myDeque = myStack; // Does not compile
</code></pre>

<p>What is the simplest way to do it?</p>

<hr>

<p>The way I would do it is:</p>

<pre><code>std::stack&lt;int, std::deque&lt;int&gt; &gt; newStack = myStack;
std::deque&lt;int&gt; myDeque;
while(!newStack.empty()){
    myDeque.push_back(newStack.top());
    newStack.pop();
}
</code></pre>

<p>but it looks a bit ugly.</p>