C++ / a working model

BOOK / SOURCE & READING RECORD

Effective STL: 50 Specific Ways to Improve Your Use of the Standard Template Library

Scott Meyers

English first edition, 2001; full Chinese edition read: 清华大学出版社2006年4月第1版第1次印刷,潘爱民、陈铭、邹开红译,ISBN7-302-12695-X;另读2011英文电子版出版社样章

READING EVIDENCE / Full text read

Effective STL: 50 Specific Ways to Improve Your Use of the Standard Template Library

Have read all substantial content of the 222-page Chinese scan: introduction, Items 1–50, bibliography, Appendices A/B (print pages 1–208, PDF 15–222). PDF 1–99 used remote OCR full text, and diagrams on pages 21, 38, and 70–71 were checked directly; after the service rate-limited, OCR was no longer requested, and PDF 100–222 were read page by page from the images, including all code, tables, and figures. The copyright page was verified as the April 2006 first Chinese edition, first printing. Also read English publisher Items 1–4, 16, 21, and 44; do not describe a full Chinese read-through as a full English read-through.

Edition, actual reading range, and original sources →

Sources

A container's equivalence relation is part of the business contract

Chinese edition Items 19–21, print 67–77; Items 44–45, 160–169; also checked English publisher Items 21, 44

Looking at Items 21 and 44 together, lookup is not merely a speed choice: an ordered container judges two keys equivalent by whether the comparator considers either ordered before the other; ordinary find depends on equality. If the business groups by number, two objects with different extra tags can be equivalent in the set without being equal by object equality. Therefore when migrating lookup methods you must first preserve the identity definition, then discuss complexity. A reverse-order comparator should swap the arguments, not simply negate the original result. Historical editions called hashed containers non-standard and discussed non-constant-time list::size; C++20 has unordered containers and list::size is constant complexity, so these old conclusions cannot be generalized as-is.

Read lasting contracts separately from era-specific limitations

Chinese edition Items 14, 28, 30, 32, 36, 39, print 53–55, 101–103, 106–110, 115–118, 128–130, 139–142; Appendices A/B, 195–208

What is worth carrying forward from the whole book is boundary awareness: reserve provides capacity without creating elements, remove compactly retains a range without shrinking the container, a reverse iterator's base points to the adjacent forward position, and a stateful predicate cannot rely on an algorithm keeping only one copy of the object. These are testable contracts. On the other hand, background that has changed includes the book's lack of copy_if, associative-container erase not returning an iterator, allocators not carrying state, and string possibly being copy-on-write; re-examine these with standard copy_if, erase returning a position, allocator_traits, and modern string rules respectively. Appendix A further reminds me that case-insensitivity is not mechanically lowercasing bytes: language, locale, and collation rules must become interface agreements. Appendix B's alternative-library advice for MSVC 4–6 is historical material only.

Related fundamentals

map and set: ordered association and the comparator contractAlgorithms: sort, boundary search, and erase-removeIterators: capability categories, ranges, and validityvector: growth, capacity, and invalidation

Original practice →