Chapter 45. BOOL

Difficulty: 7

Do we really need a builtin bool type? Why not just emulate it in the existing language? This Item reveals the answer.

Besides wchar_t (which was a typedef in C), bool is the only builtin type to be added to C++ since the ARM (Ellis90).

Could bool's effect have been duplicated without adding a builtin type? If yes, show an equivalent implementation. If no, show why possible implementations do not behave the same as the builtin bool.

Solution

Solution

The answer is: No, bool's effect could not have been duplicated without adding a builtin type. The bool builtin type, and the reserved keywords true and false, were added to C++ precisely ...

Get Exceptional C++: 47 Engineering Puzzles, Programming Problems, and Solutions now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.