| Preface |
|
xi | |
| Acknowledgments |
|
xv | |
| Introduction |
|
1 | (10) |
|
|
|
11 | (52) |
|
Choose your containers with care |
|
|
11 | (4) |
|
Beware the illusion of contaier-independent code |
|
|
15 | (5) |
|
Make copying cheap and correct for objects in containers |
|
|
20 | (3) |
|
Call empty instead of checking size() against zero |
|
|
23 | (1) |
|
Prefer range member functions to their single-element counterparts |
|
|
24 | (9) |
|
Be alert for C++'s most vexing parse |
|
|
33 | (3) |
|
When using containers of newed pointers, remember to delete the pointers before the container is destroyed |
|
|
36 | (4) |
|
Never create containers of auto_ptrs |
|
|
40 | (3) |
|
Choose carefully among erasing options |
|
|
43 | (5) |
|
Be aware of allocator conventions and restrictions |
|
|
48 | (6) |
|
Understand the legitimate uses of custom allocators |
|
|
54 | (4) |
|
Have realistic expectations about the thread safety of STL containers |
|
|
58 | (5) |
|
|
|
63 | (20) |
|
Prefer vector and string to dynamically allocated arrays |
|
|
63 | (3) |
|
Use reserve to avoid unnecessary reallocations |
|
|
66 | (2) |
|
Be aware of variations in string implementations |
|
|
68 | (6) |
|
Know how to pass vector and string data to legacy APIs |
|
|
74 | (3) |
|
Use ``the swap trick'' to trim excess capacity |
|
|
77 | (2) |
|
|
|
79 | (4) |
|
|
|
83 | (33) |
|
Understand the difference between equality and equivalence |
|
|
83 | (5) |
|
Specify comparison types for associative containers of pointers |
|
|
88 | (4) |
|
Always have comparison functions return false for equal values |
|
|
92 | (3) |
|
Avoid in-place key modification in set and multiset |
|
|
95 | (5) |
|
Consider replacing associative containers with sorted vectors |
|
|
100 | (6) |
|
Choose carefully between map::operator[] and map::insert when efficiency is important |
|
|
106 | (5) |
|
Familiarize yourself with the nonstandard hashed containers |
|
|
111 | (5) |
|
|
|
116 | (12) |
|
Prefer iterator to const_iterator, reverse_iterator, and const_reverse_iterator |
|
|
116 | (4) |
|
Use distance and advance to convert a container's const_iterators to iterators |
|
|
120 | (3) |
|
Understand how to use a reverse_iterator's base iterator |
|
|
123 | (3) |
|
Consider istreambuf_iterators for character-by-character input |
|
|
126 | (2) |
|
|
|
128 | (34) |
|
Make sure destination ranges are big enough |
|
|
129 | (4) |
|
Know your sorting options |
|
|
133 | (6) |
|
Follow remove-like algorithms by erase if you really want to remove something |
|
|
139 | (4) |
|
Be wary of remove-like algorithms on containers of pointers |
|
|
143 | (3) |
|
Note which algorithms expect sorted ranges |
|
|
146 | (4) |
|
Implement simple case-insensitive string comparisons via mismatch or lexicographical_compare |
|
|
150 | (4) |
|
Understand the proper implementation of copy_if |
|
|
154 | (2) |
|
Use accumulate or for_each to summarize ranges |
|
|
156 | (6) |
|
Functors, Functor Classes, Functions, etc |
|
|
162 | (19) |
|
Design functor classes for pass-by-value |
|
|
162 | (4) |
|
Make predicates pure functions |
|
|
166 | (3) |
|
Make functor classes adaptable |
|
|
169 | (4) |
|
Understand the reasons for ptr_fun, mem_fun, and mem_fun_ref |
|
|
173 | (4) |
|
Make sure less〈T〉 means operator〈 |
|
|
177 | (4) |
|
|
|
181 | (44) |
|
Prefer algorithm calls to hand-written loops |
|
|
181 | (9) |
|
Prefer member functions to algorithms with the same names |
|
|
190 | (2) |
|
Distinguish among count, find, binary_search, lower_bound, upper_bound, and equal_range |
|
|
192 | (9) |
|
Consider function objects instead of functions as algorithm parameters |
|
|
201 | (5) |
|
Avoid producing write-only code |
|
|
206 | (3) |
|
Always #include the proper headers |
|
|
209 | (1) |
|
Learn to decipher STL-related compiler diagnostics |
|
|
210 | (7) |
|
Familiarize yourself with STL-related web sites |
|
|
217 | (8) |
| Bibliography |
|
225 | (4) |
| Appendix A: Locales and Case-Insensitive String Comparisons |
|
229 | (10) |
| Appendix B: Remarks on Microsoft's STL Platforms |
|
239 | (6) |
| Index |
|
245 | |