Calin said:
a light breeze said:
A bool is effectively an enum { false, true }
this confirms my suspicion.
As I wrote earlier in the thread, there are plenty of additional rules about bools as a special type, especially when it comes to conversions which happen automatically behind your back. It provides much stronger guarantees than an enum.
The unscoped enumeration above, enum { false, true }
could just as easily be set to values like -1 or 42 especially on old compilers respecting older language standards. C++11 tightened the rules a lot, C++17 refined them more. A scoped enumeration or strictly enforcing modern rules, enum class MyBool { myFalse, myTrue }
adds some additional type checking so you couldn't do MyBool b = 42;
but you can still cast into it with MyBool b = MyBool(42);
and similar where you could still achieve the value of 42 stored inside.
The bool type has stronger conversion requirements built into the language. Casting or converting into bool requires whatever compiler-specific conversion is needed, casting/converting back out must only result in either the values 0 or 1, anything else is a compiler defect. That is, bool b = bool(42);
will still give you an integer value 1.