I am trying to convert a min-heap priority queue to return as a vector of ints. Is this type conversion is possible in C++;
Asked
Active
Viewed 1,051 times
-3
-
4Well, you could pop all the elements from the queue one by one, and push them to the vector. – Igor Tandetnik Jan 26 '21 at 23:55
-
2There is no implicit or explicit direct conversion. – user4581301 Jan 27 '21 at 00:03
1 Answers
2
The C++ std::priority_queue uses a container for storage https://en.cppreference.com/w/cpp/container/priority_queue
By default it is class Container = std::vector<T>
Is this what you want to get access to ? If so, though luck:
C, the underlying container (protected member object)
It is not exposed. You could derive from priority_queue and expose it, if needed. But you post is thin as to what you are actually trying to do.
Keep in mind that:
- The container doesn't store sorted elements. It is a heap, so only the first element will be correct. It might have little actual use.
This answer discusses accessing the Container: Is there a way to access the underlying container of STL container adaptors?

Jeffrey
- 11,063
- 1
- 21
- 42