How can I copy an entire vector into a queue?

前端 未结 3 956
滥情空心
滥情空心 2021-02-14 08:09

I am looking to copy the entire contents of a vector into a queue in C++. Is this a built in function or is it nessesary to loop over each element?

3条回答
  •  别那么骄傲
    2021-02-14 09:07

    Probably the best way is to directly push elements into the queue.

    std::vector v;
    ...
    std::queue q;
    for (const auto& e: v)
      q.push(e)
    

    Even using std::copy is tedious since you have to wrap the queue in an adapter (Insert into an STL queue using std::copy).

提交回复
热议问题