, std::queue std::vector. , .
std::queue- container adapter. The internal containerdefault is std::deque, but you can also set it to std::vector. The member element that holds this container is marked protectedfortunately. Therefore, you can crack it by subclassing queue.
Decision (!)
template<typename T>
struct my_queue : std::queue<T, std::vector<T>>
{
using std::queue<T, std::vector<T>>::queue;
std::vector<T>& to_vector () { return this->c; }
};
What is it!
Using
my_queue<int> q;
q.push(1);
q.push(2);
std::vector<int>& v = q.to_vector();
Demo .
source
share