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,630 of 33,346    |
|    =?ISO-8859-15?Q?Daniel_Kr=FCgler?= to Exactly. The specification    |
|    Re: Useful applications for boolean incr    |
|    02 Nov 12 14:11:13    |
   
   From: daniel.kruegler@googlemail.com   
      
   Am 02.11.2012 19:31, schrieb Stuart:   
      
   > I can only imagine one reason why someone would want to use   
   > operator++ on a bool variable, which would be that he wants to   
   > negate the value in a single line:   
   >   
   > bool negate (bool value) {   
   > return ++value;   
   > }   
      
   Yes, but that doesn't do what you expect, right?   
      
   > Apparently operator++ does not work like this   
      
   Exactly. The specification says that the result of increment on any   
   bool value is true.   
      
   > (it seems to invoke operator++ on the internal representation of a   
   > bool):   
      
   Not really, the result is specified to be true - that's it. You can   
   consider it as equivalent to converting 1 (the successor of false) or   
   2 (the successor of true) back to bool.   
      
   > The only use case for operator++ on bool I could think of was the   
   > following:   
   >   
   > #include
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca