title: Set the maximum size for a boost priority queue
body: <p>I am trying to find top n items of a list that gets populated dynamically. I thought priority-queue would be a good way to go about this. Since I need only top n, there is no point in storing anything more than the 'n' items required for my calculation. I am unable to find anything in the boost library that seems to be able to set the limit for the priority queue</p>
  
  <p>I tried using the reserve(element_count) function. The doc said that the function is used to "reserve space for the element_count elements". But that did not work the way I thought it would</p>
  
  <p>This is some sample code that I am writing. This is NOT THE USE CASE though.</p>
  
  <pre class="lang-cpp prettyprint-override"><code>int main()
  {
          int maxSize = 2; // Priority Queue (pq) is expected to hold a maximum of 2 elements at any time
          boost::heap::priority_queue&lt;int&gt; pq; // Declaration
          pq.reserve(maxSize); // I assumed this would reserve space only for 2 elements and anything more would over write the existing ones based on comparison
          pq.push(3);
          pq.push(2);
          pq.push(1); // Push should fail
          cout &lt;&lt; "Size = " &lt;&lt;pq.size() &lt;&lt; " Max Size = " &lt;&lt; (int)pq.max_size(); 
          for (int i=0; i&lt;maxSize; i++)
          {
                  int a = pq.top();
                  pq.pop();
                  cout &lt;&lt; a &lt;&lt;"\n";
          }
          return 0;
  }
  </code></pre>
  
  <p>I expected the result to be:<br>
  Size = 2 Max Size = 2<br>
  3<br>
  2</p>
  
  <p>But what I get is:</p>
  
  <p>Size = <b>3</b> Max Size = -1<br>
  3<br>
  2</p>
  
  <p>What am I missing?</p>