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

  • SEARCH
  • Home
  • 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 435753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T20:24:29+00:00 2026-05-12T20:24:29+00:00

Just now, I’m reading Josuttis’ STL book. As far as I know — c++

  • 0

Just now, I’m reading Josuttis’ STL book.

As far as I know — c++ vector is a c-array that can be reallocated. So, I understand, why after push_back() all iterators and references can become invalid.

But my question is about std::deque. As I know it is array of large blocks (c-array of c-arrays). So push_front() inserts element at the beginning and if there is no space, deque allocates new block, and places the element at allocated block’s end.

After insert() in the middle all references and iterators become invalid and I understand why — all elements are moved.
But I really misunderstand the phrase “…after push_back() and push_front() all references stays valid, but iterators don’t” (same phrase can be found @ standard:23.2.2.3)

What does it mean?! If references are valid, than deque couldn’t reallocate (== move) its elements. So why iterators become invalid? Why can’t I use them after non-moving-elements insertion? Or does the phrase mean, that I can’t be sure about iterators equality to begin() or end() and overflow?

Also, I wanna mention, that after erase() all iterators and references stay valid (except the erased one 🙂 ).

PS: please don’t answer in “standard” form: “it can’t be used because THE STANDARD says so”.
I wanna understand why, what can happen.

  • 1 1 Answer
  • 2 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-12T20:24:29+00:00Added an answer on May 12, 2026 at 8:24 pm

    I think that the reason iterators get invalidated but references not might be because of the possible deque implementation of an array of pointers to the deque’s pages that store the elements. A reference to an element in a deque will refer directly to the element in a ‘page’. However, an iterator into the deque might be dependant on the vector of pointers that point to the various pages.

    Inserting a new element into a deque at one or another end will never require reallocating and moving exsting data pages, but it might require adding to (and therefore reallocating & copying) the array of page pointers, invalidating any iterators that depended on the previous array of page pointers.

    Array of pointers           
    (if this grows                 Data Pages
     and gets copied,           (these never move
     iterators are invalid)      due to insert at ends)
    -----------------          --------------------
    
     +----------+               +----------+
     |         -+-------------->|          |
     +----------+               +----------+
     |         -+---------+     |          |
     +----------+         |     +----------+
     |         -+---+     |     |          |
     +----------+   |     |     +----------+ 
                    |     |
                    |     |
                    |     |
                    |     |     +----------+
                    |     +---->|          |
                    |           +----------+
                    |           |          |
                    |           +----------+
                    |           |          |
                    |           +----------+ 
                    |           
                    |           +----------+
                    +---------->|          |
                                +----------+
                                |          |
                                +----------+
                                |          |
                                +----------+ 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've just now started reading an Algorithms book that defined Graphs as follows: Graphs
Just now I'm looking at fixing a localization bug with a small application that
Working in Delphi7 just now, I noticed that not only a VarIsEmpty function exists,
I'm writing a little app that displays some graphics and just now I'm trying
Just now I found that static libraries in *nix systems, in other words *.a
Just now, I'm finishing the script of big portal. But how can I be
So I just now learned of the X-Robots-Tag which can be set as part
Reading over some example Objective C code just now. @property (nonatomic, strong) IBOutlet UILabel
I know NHibernate just now and it reverse my perspective about data access.Now I
Just now I came across ApplicationSettings in .NET WinForms that could handle complex types.

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.