home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c++.moderated      Moderated discussion of C++ superhackery      33,346 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 33,116 of 33,346   
   guinness.tony@googlemail.com to HungryGoat   
   Re: stl::map iterator   
   01 Jul 13 05:56:08   
   
   On Monday, 1 July 2013 08:00:02 UTC+1, HungryGoat  wrote:   
   >   
   > Hi, This code is from "The C++ standard library" by Nicolai book,   
   > page no. 178   
      
      
      
   > My question is, when we call c.erase(pos), aren't there chances that   
   > the pos iterator is invalidated by the earlier call to c.insert   
   > function.   
   >   
   > My impression is that the iterators are invalidated after any insert   
   > or delete operation.   
      
   You are probably basing that impression on the behaviour of   
   std::vector.   
      
   For many other containers, (e.g. std::list, std::set, std::map)   
   different iterator-preservation/invalidation rules apply.  In your   
   specific case (std::map, an associative container), the Standard says   
      
   [associative.reqmts].para 9:   
      
   "The insert members shall not affect the validity of iterators and   
   references to the container, and the erase members shall invalidate   
   only iterators and references to the erased elements."   
      
   Cheers,   
   Tony.   
      
      
   --   
         [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
         [ comp.lang.c++.moderated.    First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca