The interface of STL and boost priority queues includes

```
T const &   top () const;
void    pop ();

```

The latter deletes the top element. But what if I want to keep using that element after I pop() it, and I want to avoid copying? E.g., suppose I have a `priority_queue<T> pq`. I'd like to write

```
const T& first = pq.top();      
pq.pop();
const T& second = pq.top();
analyze(second);
analyze(first);      // first *after* second

```

Unfortunately, as soon as I pop(), the first reference becomes invalid, so I get a segfault. 

I'd prefer a solution like java's `nextElement()`, which returns `top()` and does a `pop()`, but deletes the element only when it goes out of scope. That way I don't need to keep track of what to `pop()` and when. However, using `priority_queue<shared_pointer<T> >` doesn't seem to help, because taking a ref to a `shared_pointer` doesn't increase its use\_count. 

In case it matters, I prefer to use `boost::fibonacci_heap` for its efficient `push()`. 

Any ideas or pointers? Thanks!