I have the following use case:
containerTypeX
object to which I insert many elements at the front- After the
containerTypeX
object has everything inserted, thecontainerXType
object needs to be converted to astd::vector
For containerTypeX
I chose std::deque
over std::vector
, because as far as I know inserting at the begin of a std::vector
is not efficient.
But now I have to convert the std::deque
to a std::vector
and do not want to move every single element from the queue to the vector separately like
v.emplace_back(std::move(q.front()));
1) Is there a way to directly convert my queue to a vector that I am missing?
2) Should I use a LIFO container like std::stack
instead of std::deque
as I am only inserting one one side? But this will leave me the problem that in addition the element ordering needs to be reversed when converted to the std::vector
...
Related Question: How to convert std::queue to std::vector