C++ - how to copy elements from std::priority_queue to std::vector
<p>For example, I want to pick out the k-th largest elements from a input vector.</p>

<p>I know it can be better done with QuickSelect std::nth_element.</p>

<p>My question is how to copy the underlying container std::vector of std::priority_queue to another vector, rather than solve this coding problem.</p>

<pre><code>priority_queue&lt;int, vector&lt;int&gt;, greater&lt;int&gt;&gt; pq;
for (int num : nums) {
    pq.push(num);
    if (pq.size() &gt; k) {
        pq.pop();
    }
}
</code></pre>

<p>My way is stupid:</p>

<pre><code>vector&lt;int&gt; res;
while (!pq.empty()) {
    res.push_back(pq.top());
    pq.pop();
}
</code></pre>

<p>Is there better way to do it?</p>

<p>Can we do it like</p>

<pre><code>vector&lt;int&gt; res = pq;
</code></pre>

<p>The top k elements do not need to be ordered.</p>