title: Pre-allocate space for C++ STL queue
body: <p>I'm writing a radix sort algorithm using queues and I would like to have a STL queue allocate space before I start adding things to the queue so that I can avoid constant dynamic resizing operations. </p>
  
  <p>Even though this doesn't exist, I want something with the effect of...</p>
  
  <pre><code>queue&lt;int&gt; qs(N);
  for(int i=0;i&lt;N;++i)
    qs.push(rand());
  </code></pre>
  
  <p>in such a way that it will not dynamically allocate any memory during the loop.</p>
  
  <p>The actual code in question...</p>
  
  <pre><code>void radix_sort()
  {
  // Biggest number?
  int max=-1;
  for(int i=0;i&lt;N;++i)
      if(a[i]&gt;max)
          max = a[i];
  
  // How many digits in it
  int maxdigits=1;
  while(max /= 10) maxdigits++;
  
  // Create some buckets.
  deque&lt;int&gt; b[10];
  for(int i=0;i&lt;10;++i)
      b[i] = deque&lt;int&gt;(N);
  
  int div=1;
  // Radix Sort by digits
  for(int d=1;d&lt;=maxdigits;++d)
  {
      if(d&gt;1)
          div*=10;
  
      // Queue
      for(int i=0;i&lt;N;++i)
          b[ (a[i]/div) % 10 ].push_front(a[i]);
  
      // Dequeue
      int k=0;    
      for(int q=0;q&lt;10;++q)
          while(b[q].size() &gt; 0)
          {
              a[k++] = b[q].back();
              b[q].pop_back();
          }
  }
  }
  </code></pre>