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?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you make a new queue, you can use the constructor:
(You can change the underlying container to taste, though
dequeis probably the best.)If the queue already exists, there’s no range-based algorithm, though, you can easily write your own:
As an aside: If your algorithm requires that amount of flexibility, you’re probably better of just using a
std::dequein the first place. The container adapters (queueandstack) should only be used if you want to say explicitly, “this is the behaviour I want” (i.e. push/pop).