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,669 of 33,346    |
|    =?ISO-8859-15?Q?Daniel_Kr=FCgler?= to All    |
|    Re: Useful applications for boolean incr    |
|    21 Nov 12 21:22:13    |
   
   From: daniel.kruegler@googlemail.com   
      
   Am 21.11.2012 21:47, schrieb Dave Harris:   
   > daniel.kruegler@googlemail.com (Daniel Krügler) wrote (abridged):   
   >> I would like to know whether there are C++ projects or maybe   
   >> use-cases out in the wild that have been found useful   
   >> applications for the existing language support of pre- and   
   >> post-increment on bool values,   
   >> [...]   
   >> If anyone feels that this removal would break relevant code or   
   >> idioms, please respond to this query.   
   >   
   > What about:   
   >   
   > void demo() {   
   > static bool done = false;   
   > if (!done++)   
   > do_once();   
   > }   
   >   
   > The idea being that do_once() is invoked the first time demo() is called   
   > and not subsequence times.   
   >   
   > I have not seen this in real code. Personally I'd write:   
   >   
   > void demo() {   
   > static bool done = false;   
   > if (!done) {   
   > done = true;   
   > do_once();   
   > }   
   > }   
   >   
   > This is 2 lines longer, but the other relies on obscure semantics.   
      
   Agreed. In fact, your example is the only one that has presented to me   
   three times by independent parties (not only in this thread, so I'm not   
   nit-picking with my remark), but as you say the alternative form is the   
   only one that I have found personally in real code.   
      
   Thanks for your input and example,   
      
   Daniel Krügler   
      
      
      
   --   
    [ 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