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,077 of 33,346   
   Dave Abrahams to All   
   Re: Why does range based for loop requir   
   31 Mar 12 21:01:53   
   
   From: dave@boostpro.com   
      
   on Wed Mar 28 2012, Pete Becker  wrote:   
      
   > On 2012-03-28 02:46:07 +0000, Dave Abrahams said:   
   >   
   >> on Sat Mar 24 2012, Pete Becker  wrote:   
   >>   
   >>> On 2012-03-24 05:31:44 +0000, Frank Birbacher said:   
   >>>   
   >>>>   
   >>>> // not allowed in C++11, but I want it to work:   
   >>>> int i;   
   >>>> for(i : vec) {...}   
   >>>>   
   >>>   
   >>> What should the value of i be after the loop? More generally, what do   
   >>> you want to be able to do with i after this loop?   
   >>   
   >> The value of i is most useful if you break from the loop.  BOOST_FOREACH   
   >> supports Frank's usage and frankly I'm surprised to learn that C++11's   
   >> native construct doesn't.   
   >   
   > Okay, that's reasonable. But what if you don't exit early? I suppose   
   > the value could be the last element, but that's artificial; the "true"   
   > value is *end, but end doesn't have to be dereferenceable.   
      
   I don't understand why you'd call that "artificial," or on what basis   
   you're calling some possibly non-existent value "true."  The value of   
   the last element is the only value that could possibly be left there,   
   assuming the loop is entered at all.   
      
   --   
   Dave Abrahams   
   BoostPro Computing   
   http://www.boostpro.com   
      
      
         [ 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