C++ / a working model

BOOK / SOURCE & READING RECORD

More Exceptional C++: 40 New Engineering Puzzles, Programming Problems, and Solutions

Herb Sutter

1st edition, copyright 2002; publisher PDFs carry November 27, 2001 production timestamps

READING EVIDENCE / Partial text read

More Exceptional C++: 40 New Engineering Puzzles, Programming Problems, and Solutions

Finished reading the publisher's Item 2 (standalone PDF, 5 pages) and Item 3 (9 pages). All publicly available text of Item 1 (6 pages) and Item 4 (14 pages) has also been read, but the files end respectively at “Good sepa-” and “foreordained base class”, so completeness of the endings cannot be guaranteed; counted as visible excerpts. Items 5–40 and Appendices A/B unread; the full book text was not obtained, and original GotW articles do not substitute for the book.

Edition, actual reading range, and original sources →

Sources

A condition may carry configuration, but must not secretly carry position

Item 2 standalone PDF pp. 2–5; Item 3 standalone PDF pp. 5–9

The real boundary shown by Items 2–3 is that the algorithm owns the traversal strategy while the caller owns the judgment rule. A predicate that captures a threshold and keeps it unchanged has data, yet every copy still answers the same question; a predicate that treats the number of calls as the current position hides control flow inside the condition, so copying or a different call order changes its meaning. To delete a position, use an explicit position operation; to delete elements matching a value condition, let the condition depend only on the element and stable configuration. C++20 erase_if simplifies the erase-remove idiom but does not provide guarantees against this confusion. The handwritten reference counting at the end of the original book is used to illustrate shared state; one cannot infer from it that shared state solves order dependence, nor should old smart pointers be copied into new projects.

Related fundamentals

Algorithms: sort, boundary search, and erase-removeLambda capture: a closure is an object with a lifetimeIterators: capability categories, ranges, and validityType traits and if constexpr compile-time branching

Original practice →