title: Implementing a priority queue that can be iterated over in C++
body: <p>I need to implement a priority queue for a project, but the STL's <code>priority_queue</code> is not indicated since we need to iterate over all elements and remove them randomly.</p>
  
  <p>We are thinking about using the STL's <code>set</code> for this, wrapping it in a class to make it an ADT.</p>
  
  <p>Is there a smarter solution for this?</p>
  
  <p>How can we make it so some of <code>set</code>'s public member functions can be used publicly? We're interested in iterators, etc.</p>
  
  <p>Apparently deriving the STL is unwise because of the lack of virtual destructors :/</p>
  
  <hr>
  
  <p>New code:</p>
  
  <pre><code>#ifndef PRIORITYQUEUE_H_
  #define PRIORITYQUEUE_H_
  
  #include &lt;set&gt;
  
  template&lt;typename T, template&lt;typename X&gt; class impl_type = std::set&gt;
  class PriorityQueue {
      typedef impl_type&lt;T&gt; set_type;
      typedef typename set_type::iterator iterator;
  public:
      void push(const T&amp; x) {
          insert(x);
  
      }
  
      void pop() {
          erase(begin());
      }
  
      const T&amp; top() const {
          return *begin();
      }
  };
  
  #endif /* PRIORITYQUEUE_H_ */
  </code></pre>
  
  <p>So, we currently have this. The compiler doesn't complain about insert, but it does complain about <code>erase(begin())</code> and <code>return *begin()</code>:</p>
  
  <p><code>there are no arguments to 'begin' that depend on a template parameter, so a declaration of 'begin' must be available</code></p>
  
  <p>Why is this?</p>