title: priority queue: Using an object to compare instead of a class
body: <p>starting with <code>priority_queue</code>s, I have a problem like this: I need elements to be stored in a queue, but the criterion how they are sorted is not included in the elements itself, but somewhere different, like in a map:</p>
  
  <pre><code>std::map&lt;element, value&gt; element_values;
  std::priority_queue&lt;element&gt; queue;
  </code></pre>
  
  <p>What I need now is something like that:</p>
  
  <pre><code>struct Comp
  {
      std::map&lt;...&gt;&amp; the_map;
      Cpmp(std::map&lt;...&gt; _map) : the_map(_map) {}
  
      bool operator() (element a, element b)
      {
          return the_map[a] &lt; the_map[b];
      }
   }
  
   Comp comp(element_values);
   std::priority_queue&lt;element, std::vector&lt;element&gt;, comp&gt; queue; // does not work
   std::priority_queue&lt;element, std::vector&lt;element&gt;, Comp&gt; queue; // does work but I'd not be able to pass values to the constructor
  </code></pre>
  
  <p>The elements itself have no intrensic order. A workaround would be to define a struct wrapping this stuff up, but maybe someone knows a smarter way. I also thought about providing a compare function only valid in my current scope (which itself is a function), but as far as I know C++ does not support that, at least not with capturing local variables like I would need.</p>