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,049 of 33,346    |
|    Seungbeom Kim to Frank Birbacher    |
|    Re: Why does range based for loop requir    |
|    24 Mar 12 23:15:35    |
   
   From: musiphil@bawi.org   
      
   On 2012-03-24 13:55, Frank Birbacher wrote:   
   > Am 24.03.12 12:35, schrieb Pete Becker:   
   >> 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?   
   >   
   > Yeah, I've thought about this, too. The first idea is to use "break"   
   > inside the loop and use the loop variable as the "found element." But   
   > when you leave the loop regularily you wouldn't know if the variable   
   > contains the found element or just the last one.   
   >   
   > int i;   
   > for(i : vec) {   
   > if(pred(i))   
   > break;   
   > }   
   > // found or not?   
   >   
   > So, is the non-usefulness the rationale behind the design of the range   
   > loop?   
      
   Maybe, but I do not really know. The usefulness depends on the situation,   
   and it's for the individual programmer to decide, not for the committee.   
   For example, the programmer may know in advance that vec stores only   
   non-negative integers, and thus may have set i to -1 before the loop.   
   And after all, one of the design rules of C++ is "It is more important   
   to allow a useful feature than to prevent every misuse," isn't it? :)   
      
   --   
   Seungbeom Kim   
      
      
    [ 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