Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6469721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:01:36+00:00 2026-05-25T06:01:36+00:00

The std::queue is implemented with a deque by default. std::deque has the subscript operator,

  • 0

The std::queue is implemented with a deque by default. std::deque has the subscript operator, operator[], and is probably implemented with arrays. So why doesn’t std::queue have operator[]?

I realize you could have a queue with a list as the underlying container. (std::queue<int, std::list<int>>.) But even if that would make the subscript operator slow, is that really a good reason not to include it? That’s the only reason I can think of that it is not included.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T06:01:36+00:00Added an answer on May 25, 2026 at 6:01 am

    Because the definition of queue doesn’t support such interface. Queue is a FIFO data structure which means First In First Out. Queue supports enqueue and dequeue operations.

    Imagine of queue as pipe : you insert data into one end and from the other end you take it out – one by one. Inserting data is called enqueue and taking them out is called dequeue. The C++ standard library has std::queue which defines both these operations: push() is the name of enqueue operation, and dequeue operation has been splitted into two steps namely front() followed by pop(). The rationale why dequeue has been split into two steps is to give strong exception guarantee1.

    Wikipedia explains this briefly,

    A queue is a particular kind of collection in which the entities in the collection are kept in order and the principal (or only) operations on the collection are the addition of entities to the rear terminal position and removal of entities from the front terminal position. This makes the queue a First-In-First-Out (FIFO) data structure. In a FIFO data structure, the first element added to the queue will be the first one to be removed. This is equivalent to the requirement that once an element is added, all elements that were added before have to be removed before the new element can be invoked. A queue is an example of a linear data structure.

    1. If you want to know how exacly it gives strong exception guarantee, then you can start another topic, because it’s very long story, and requires lots of patience to understand it properly. I would suggest you to read Exceptional C++ by Herb Sutter for this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a std::queue that is wrapped as a templated class to make a
I have typedef std::queue<MyObject*> InputQueue; std::vector<InputQueue> inp_queue; Now what I want to do is
My priority queue declared as: std::priority_queue<*MyClass> queue; class MyClass { bool operator<( const MyClass*
Does anyone know why std::queue, std::stack, and std::priority_queue don't provide a clear() member function?
std::map<any, string> is not working so I wonder if there's another approach to have
std::swap() is used by many std containers (such as std::list and std::vector ) during
In my project I use the std::queue class. I would like to know what
I'm trying to use BOOST_FOREACH for iterating through the std::queue. But there isn't iterators
I am implementing a C++ message queue based on a std::queue. As I need
I'd like to use std::copy to insert elements into a queue like this: vector<int>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.