The base container is a protected data item named c (see here for more details). Therefore, you can always inherit from std::priority_queue and export a couple of iterators over this container (if any).
As a minimal working example:
#include<queue> #include<iostream> struct MyPriorityQueue: std::priority_queue<int> { auto begin() const { return c.begin(); } auto end() const { return c.end(); } }; int main() { MyPriorityQueue pq; pq.push(0); pq.push(1); for(auto &v: pq) { std::cout << v << std::endl; } }
Note: inheritance from data structures in the std:: usually discouraged.
That being said, it works as a minimum.
The code above works in C ++ 14.
Below is a slightly modified version that also works in C ++ 11, as noted in the comments:
#include<queue> #include<iostream> struct MyPriorityQueue: std::priority_queue<int> { decltype(c.begin()) begin() const { return c.begin(); } decltype(c.end()) end() const { return c.end(); } }; int main() { MyPriorityQueue pq; pq.push(0); pq.push(1); for(auto &v: pq) { std::cout << v << std::endl; } }
source share