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,661 of 33,346    |
|    Dave Harris to daniel.kruegler@googlemail.com    |
|    Re: Useful applications for boolean incr    |
|    21 Nov 12 12:47:03    |
   
   From: brangdon@cix.compulink.co.uk   
      
   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.   
      
   -- Dave Harris, Nottingham, UK.   
      
      
   --   
    [ 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