Appendix A. Beyond Effective C++
Effective C++ covers what I consider to be the most important general guidelines for practicing C++ programmers, but if you're interested in more ways to improve your effectiveness, I encourage you to examine my other C++ books, More Effective C++ and Effective STL.
More Effective C++ covers additional programming guidelines and includes extensive treatments of topics such as efficiency and programming with exceptions. It also describes important C++ programming techniques like smart pointers, reference counting, and proxy objects.
Effective STL is a guideline-oriented book like Effective C++, but it focuses exclusively on making effective use of the Standard Template Library.
Tables of contents for both books are summarized below.
Contents of More Effective C++
Distinguish between pointers and references
Prefer C++-style casts
Never treat arrays polymorphically
Avoid gratuitous default constructors
Be wary of user-defined conversion functions
Distinguish between prefix and postfix forms of increment and decrement operators
Never overload &&, ||, or,
Understand the different meanings of new and delete
Use destructors to prevent resource leaks
Prevent resource leaks in constructors
Prevent exceptions from leaving destructors
Understand how throwing an exception differs from passing a parameter or calling a virtual function
Catch exceptions by reference
Use exception specifications judiciously
Understand the costs of exception handling
Remember the 80-20 rule
Consider using lazy evaluation
Amortize the cost of expected computations
Understand the origin of temporary objects
Facilitate the return value optimization
Overload to avoid implicit type conversions
Consider using op= instead of stand-alone op
Consider alternative libraries
Understand the costs of virtual functions, multiple inheritance, virtual base classes, and RTTI
Virtualizing constructors and non-member functions
Limiting the number of objects of a class
Requiring or prohibiting heap-based objects
Making functions virtual with respect to more than one object
Program in the future tense
Make non-leaf classes abstract
Understand how to combine C++ and C in the same program
Familiarize yourself with the language standard
Contents of Effective STL
Chapter 1: Containers
Choose your containers with care.
Beware the illusion of container-independent code.
Make copying cheap and correct for objects in containers.
Call empty instead of checking size() against zero.
Prefer range member functions to their single-element counterparts.
Be alert for C++'s most vexing parse.
When using containers of newed pointers, remember to delete the pointers before the container is destroyed.
Never create containers of auto_ptrs.
Choose carefully among erasing options.
Be aware of allocator conventions and restrictions.
Understand the legitimate uses of custom allocators.
Have realistic expectations about the thread safety of STL containers.
Chapter 2: vector and string
Prefer vector and string to dynamically allocated arrays.
Use reserve to avoid unnecessary reallocations.
Be aware of variations in string implementations.
Know how to pass vector and string data to legacy APIs.
Use "the swap TRick" to trim excess capacity.
Avoid using vector<bool>.
Chapter 3: Associative Containers
Understand the difference between equality and equivalence.
Specify comparison types for associative containers of pointers.
Always have comparison functions return false for equal values.
Avoid in-place key modification in set and multiset.
Consider replacing associative containers with sorted vectors.
Choose carefully between map::operator and map::insert when efficiency is important.
Familiarize yourself with the nonstandard hashed containers.
Chapter 4: Iterators
Prefer iterator to const_iterator, reverse_iterator, and const_reverse_iterator.
Use distance and advance to convert a container's const_iterators to iterators.
Understand how to use a reverse_iterator's base iterator.
Consider istreambuf_iterators for character-by-character input.
Chapter 5: Algorithms
Make sure destination ranges are big enough.
Know your sorting options.
Follow remove-like algorithms by erase if you really want to remove something.
Be wary of remove-like algorithms on containers of pointers.
Note which algorithms expect sorted ranges.
Implement simple case-insensitive string comparisons via mismatch or lexicographical_compare.
Understand the proper implementation of copy_if.
Use accumulate or for_each to summarize ranges.
Chapter 6: Functors, Functor Classes, Functions, etc.
Design functor classes for pass-by-value.
Make predicates pure functions.
Make functor classes adaptable.
Understand the reasons for ptr_fun, mem_fun, and mem_fun_ref.
Make sure less<T> means operator<.
Chapter 7: Programming with the STL
Prefer algorithm calls to hand-written loops.
Prefer member functions to algorithms with the same names.
Distinguish among count, find, binary_search, lower_bound, upper_bound, and equal_range.
Consider function objects instead of functions as algorithm parameters.
Avoid producing write-only code.
Always #include the proper headers.
Learn to decipher STL-related compiler diagnostics.
Familiarize yourself with STL-related web sites.