From: kaba@nowhere.com   
      
   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).   
      
   For the implementer of a data structure it often happens that the   
   container of choice to store objects, say vertices of a graph, is the   
   doubly-linked list (std::list), because it preserves the identity of the   
   objects and supports constant-time inserts and erases. Thus, when I   
   create a new vertex to my graph, I will call push_back, or emplace_back   
   of the vertex-list to create a new vertex. To return the newly-created   
   vertex I need to obtain an iterator to this. This is the reoccuring   
   use-case.   
      
   --   
   http://kaba.hilvi.org   
      
      
    [ 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)   
|