Safe bool idiom
summary
A small experiment replaces the old safe bool idiom with C++11's explicit operator bool and triggers three concrete breakages: expected loss of implicit conversions, failing comparisons against literal 0 unless operator==(..., nullptr_t) overloads are added, and a surprising third case where returning a pimpl-held testable type no longer converts because return does not perform explicit conversions. A minimal patch compiles client code nowhere — the fix is local casts or API workarounds, so the library keeps the old idiom for compatibility.
AI-written summary · about
chapters (6)
- 0:00Start
- 1:16Without the Safe Bool Idiom struct Testable
- 3:21implicit conversions
- 3:51comparison against literal 0
- 4:58return statements
- 5:46Solution: must change the code
related talks
01h 02mImplicit Conversions Considered Harmful
56mEvolving a Nice Trick
42mWhat If We Pretended Unsafe Code Was Nice, And Then It Was?
01h 05mThe real problem of C++
57mBetter Code: Exploring Validity in C++
15mNon-binary Rust: Between Safe and Unsafe
01h 01mEmbracing PODs Safely Until They Die
01h 01mBack to Basics: C++ API Design
