Click for commercial
licensing information.
Scott Meyers Training Courses
Effective STL Programming
The STL is revolutionary, but learning to use it well is a challenge. This seminar, based on Meyers' Effective STL, reveals the critical rules of thumb employed by the experts -- the things they almost always do or almost always avoid doing -- to get the most out of the library.
Course Highlights
Participants will gain:
- Insights into the behavior of sequence, associative, contiguous-memory, and node-based containers, including new containers specified in TR1.
- Knowledge of techniques to use both containers and algorithms most efficiently.
- An understanding of the applications and limitations of STL allocators.
Each attendee will also receive a copy of Effective STL.
Who Should Attend
Systems designers, programmers, and technical managers involved in the design, implementation, and maintenance of production libraries and applications using the STL. Participants should already know the basic features of the STL (e.g., containers, iterators, algorithms, and function objects), but expertise is not expected. People who have learned the STL recently (e.g., from Meyers' Introductory STL course), as well as people who have been programming with it for some time, will come away from this seminar with useful, practical, proven information.
Format
Lecture and question/answer. There are no hands-on exercises, but participants are welcome to use their computers to experiment with the course material as it is presented.
Length
Two full days (six to seven lecture hours per day).
Detailed Topic Outline
- Preliminaries:
- TR1 and Boost
- The behavior of remove
- The erase-remove idiom
- remove and containers of pointers
- Algorithms vs. same-named member functions
- Equality vs. equivalence
- Containers:
- Choose your containers with care
- Sequence containers vs. associative containers
- Contiguous-memory containers vs. node-based containers
- Ways in which containers differ
- Beware the illusion of container-independent code
- Using abstraction to preserve flexibility
- Why range member functions are preferable to their single-element counterparts
- Avoiding resource leaks when storing pointers
- Why containers should never hold auto_ptrs
- Choosing among erasing options:
- Erasing simple values
- Erasing elements satisfying a predicate
- Erasing and performing arbitrary actions
- Thread-safety and STL containers
- Choose your containers with care
- vector and string
- Why vector and string are preferable to dynamically allocated arrays
- Use reserve to minimize memory reallocations in
vector and string.
- Using "the swap trick" to perform "shrink to fit."
- The wide variety of string implementations
- Using vector and string with C APIs.
- Associative Containers:
- Why comparison functions should always return false for equal values
- Issues involved in in-place modification of set and multiset elements
- Why sorted vectors can be superior to
sets and maps for lookup-intensive applications.
- std::binary_search vs. std::lower_bound vs. std::equal_range
- An overview of containers based on hash tables
- Algorithms:
- Choosing among sort, stable_sort, partition, stable_partition, and nth_element
- Understanding the algorithms that work with sorted ranges
- Implementing copy_if
- The adaptability problem
- Adding adaptability via std::ptr_fun and std::tr1::function
- Functors, Functor Classes, Functions, etc.:
- Why functor classes should be designed for pass-by-value
- How std::tr1::shared_ptr can help
- Why predicates should be pure functions
- Why functor classes should be adaptable
- TR1 and adaptability
- Why less<T> should always mean operator<
- Why functor classes should be designed for pass-by-value
- Programming with the STL:
- Why algorithm calls are usually preferable to hand-written loops:
- Efficiency
- Correctness
- Comprehensibility
- The Boost Lambda library
- Why function objects are more efficient than functions
- Choosing among count, find, binary_search, lower_bound, upper_bound, and equal_range
- #include-related portability headaches
- Why algorithm calls are usually preferable to hand-written loops:
- Allocators
- Original goals and ultimate limitations
- Allocators vs. operators new/new[]/delete/delete[]
- Allocators and node-based containers
- rebind
- Legitimate uses of allocators
- A shared-memory allocator
- A complete sample allocator
- Further Information
For more information on this course, contact Scott directly.

