Topic: question about bool


Author: clamage@Eng.Sun.COM (Steve Clamage)
Date: 1998/03/29
Raw View
In article 6fgd6dINNu8@oasys.dt.navy.mil, cswager@oasys.dt.navy.mil (C.R.Swager) writes:
>It seems to me that a bool, since it only has two states, would
>naturally use the ++ operator to toggle it's state.  Is there some
>reason that the standard does not require this or is it just that my
>implementation is not working properly?

I wouldn't agree that "increment" is the natural way to spell "toggle".

It might make sense to think of ++ as toggling a bool operand if
bool were defined to be a one-bit unsigned arithmetic type, but
it is not defined that way. Bool is defined to have two values,
"true" and "false", and it is not specified how those values are
represented. In addition, arithmetic is not defined for the bool type.

For the bool type, ++ is defined to set the operand to "true",
but using ++ for that purpose is deprecated. You can toggle a bool
by writing, for example, "b = ! b;".

---
Steve Clamage, stephen.clamage@sun.com
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]