Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

doctorsixstring

std::queue "peek()"

This topic is 5585 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is there a way to extract the data items in an STL queue without changing the contents of the queue? I know I could just pop all the elements off the list then push them back on, but I was hoping there would be a better way (i.e. a Peek()-style function). I couldn''t find anything in the documentation, but I may have missed something (I haven''t used STL too much yet). Thanks, Mike

Share this post


Link to post
Share on other sites
Advertisement
top() will return a reference to the first element. If you want to access any element but the first, you shouldn''t be using a queue. (If, for some reason, these incompatible requirements are necessary, just use a list to get queue-like behaviour.)

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!