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 32,501 of 33,346   
   Nevin ":-]" Liber to All   
   Re: Why doesn't push_back return an iter   
   24 Jul 12 18:07:10   
   
   From: nevin@eviloverlord.com   
      
   In article , Kaba    
   wrote:   
      
   > 24.7.2012 7:52, Nevin ":-]" Liber wrote:   
   > > In article ,   
   > >    Seungbeom Kim  wrote:   
   > >   
   > >> I agree that push_back(), etc. returning the iterator would be useful   
   > >   
   > > What is the use case for this?   
   >   
   > In general, you wish to create new data structures based on existing   
   > data structures. To refer to a part in a data structure you need   
   > iterators. This is essential in being able to obtain efficient data   
   > structures.   
   >   
   > In the new data structure you use existing data structures to refer to   
   > each other in useful ways. Therefore, when you create a part, you are   
   > not just creating it to be stored and later be traversed as part of a   
   > sequence (say). Rather, you are creating it to be referred to _directly_   
   > (giving you strict constant-time access and direct identification for,   
   > say, removal).   
      
   Except for list (which is node based), this gets dangerous, as iterators   
   can be invalidated at the drop of a hat.   
      
   For that reason, I wouldn't want to see it in the general container   
   interface; it just isn't that hard to use insert/emplace when you need   
   this functionality.  For the sake of consistency, I also wouldn't want   
   to see it in push_back/emplace_back for list.   
      
   As for push_front/emplace_front, begin() gets you that same iterator.   
      
   --   
   Nevin ":-)" Liber     
      
      
         [ 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