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,497 of 33,346   
   Kaba to goran.pusic@gmail.com   
   Re: Why doesn't push_back return an iter   
   24 Jul 12 11:51:48   
   
   From: kaba@nowhere.com   
      
   23.7.2012 22:16, goran.pusic@gmail.com wrote:   
   > On Monday, July 23, 2012 4:15:18 AM UTC+2, Kaba wrote:   
   >> Hi,   
   >>   
   >> A small but annoying piece of STL is that the push_back and   
   >> push_front member functions of std::list (say) do not return an   
   >> iterator to the created element. This results in having to do   
   >> something like   
   >   
   > Hmmm, OK, but the alternative is returning an object from the method.   
   > If that object isn't used often enough, that's a waste.  OTOH, if you   
   > need this often enough, you could make it into a function, I guess.   
      
   First, in my opinion, such micro-optimizations should not in general   
   hinder the design of usable interfaces (although in general time- and   
   space-complexity must be considered in design). Second, my intuition   
   says that the returned iterator will be optimized away by the compiler   
   anyway. Perhaps someone can correct if my intuition is wrong. I tried to   
   see it myself from the generated assembler code for this..   
      
   #include    
   std::list a;   
   int main()   
   {   
       a.insert(a.end(), 1);   
       return 0;   
   }   
      
   ... but I had a hard time seeing whether some code was generated for the   
   returned iterator or not. In any case, even if some code was generated,   
   the loss in performance is negligble. In such cases usability and   
   understandability should always come first.   
      
   --   
   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)   

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


(c) 1994,  bbs@darkrealms.ca