Talk:cpp/container/priority queue/top


The C++11 changes seems really strange. I don't have the latest standard, but it looks just wrong to me, and I can't find any discussion inside the c++ workgroups regarding them.

First, changing the type to non-const mean that we can make the heap invalid. It will be just like making the key in a map non-const, and remove the whole reason why you'll want a priority_queue instead of deque container (for preserving the heap invariants, that's it).

After that, calling the back method instead of the front aren't just backward compatible, but is also not consistent with the way the make_heap algorithm (and related) is working (unless you used the reverse iterators, but that would be weird).

Finally, it just looks like the definition of stack::top, so, may be that's where the error came from ?

You're correct, there's no non-const overload of top(). I have the standard and can confirm this. Thanks for the correction! -- P12 11:38, 6 May 2012 (PDT)