Thinking in C++, 2nd ed. Volume 2 Revision 4.0 - Contents
Thinking in C++, 2nd ed. Volume 2 Revision 4.0 - Title Page
Preface
What’s new in the second edition
What’s in Volume 2 of this book
How to get Volume 2
Prerequisites
Learning C++
Goals
Chapters
Exercises
Exercise solutions
Source code
Language standards
Language support
Seminars, CD Roms & consulting
Errors
Acknowledgements
Part 1: Building Stable Systems
1: Exception handling
Error handling in C
Throwing an exception
Catching an exception
The try block
Exception handlers
Termination vs. resumption
The exception specification
unexpected( )
set_unexpected( )
Better exception specifications?
Catching any exception
Rethrowing an exception
Uncaught exceptions
terminate( )
set_terminate( )
Function-level try blocks
Cleaning up
Constructors
Making everything an object
Exception matching
Standard exceptions
Programming with exceptions
When to avoid exceptions
Not for asynchronous events
Not for ordinary error conditions
Not for flow-of-control
You’re not forced to use exceptions
New exceptions, old code
Typical uses of exceptions
Always use exception specifications
Start with standard exceptions
Nest your own exceptions
Use exception hierarchies
Multiple inheritance
Catch by reference, not by value
Throw exceptions in constructors
Don’t cause exceptions in destructors
Avoid naked pointers
Overhead
Summary
Exercises
2: Defensive Programming
Assertions
Design by Contract
The Simplest Automated Unit Test Framework that could Possibly Work
Automated Testing
The TestSuite Framework
Test Suites
The Test Framework Code
Exercises
3: Debugging Techniques
Shared objects & reference counting
Reference-counted class hierarchies
Debugging
Trace macros
Trace file
Abstract base class for debugging
Finding memory leaks
Tracking new/delete & malloc/free
The canonical object & singly-rooted hierarchies
An extended canonical form
Exercises
Part 2: The Standard C++ Library
Library overview
4: Strings in Depth
What’s in a string
Creating and initializing C++ strings
Initialization limitations
Operating on strings
Appending, inserting and concatenating strings
Replacing string characters
Simple character replacement using the STL replace( ) algorithm
Concatenation using non-member overloaded operators
Searching in strings
Finding in reverse
Finding first/last of a set
Removing characters from strings
Stripping HTML tags
Comparing strings
Indexing with [ ] vs. at( )
Using iterators
Iterating in reverse
Strings and character traits
A string application
Summary
Exercises
5: Iostreams
Why iostreams?
True wrapping
Iostreams to the rescue
Sneak preview of operator overloading
Inserters and extractors
Manipulators
Common usage
Line-oriented input
Overloaded versions of get( )
Reading raw bytes
Error handling
File iostreams
Open modes
Iostream buffering
Using get( ) with a streambuf
Seeking in iostreams
Creating read/write files
stringstreams
strstreams
User-allocated storage
Output strstreams
Automatic storage allocation
Proving movement
A better way
Output stream formatting
Internal formatting data
Format fields
Width, fill and precision
An exhaustive example
Formatting manipulators
Manipulators with arguments
Creating manipulators
Effectors
Iostream examples
Code generation
Maintaining class library source
Detecting compiler errors
A simple datalogger
Generating test data
Verifying & viewing the data
Counting editor
Breaking up big files
Locales
Summary
Exercises
6: Templates in depth
Nontype template arguments
Default template arguments
The typename keyword
Typedefing a typename
Using typename instead of class
Function templates
A string conversion system
A memory allocation system
Type induction in function templates
Taking the address of a generated function template
Local classes in templates
Applying a function to an STL sequence
Expression templates
Template-templates
Member function templates
Why virtual member template functions are disallowed
Nested template classes
Template specializations
Full specialization
Partial Specialization
A practical example
Pointer specialization
Partial ordering of function templates
Design & efficiency
Preventing template bloat
Explicit instantiation
Explicit specification of template functions
Controlling template instantiation
The inclusion vs. separation models
The export keyword
Template programming idioms
The “curiously-recurring template”
Traits
Implementing Locales
Summary
Exercises
7: STL Containers & Iterators
Containers and iterators
STL reference documentation
The Standard Template Library
The basic concepts
Containers of strings
Inheriting from STL containers
A plethora of iterators
Iterators in reversible containers
Iterator categories
Input: read-only, one pass
Output: write-only, one pass
Forward: multiple read/write
Bidirectional: operator--
Random-access: like a pointer
Is this really important?
Predefined iterators
IO stream iterators
Manipulating raw storage
Basic sequences: vector, list & deque
Basic sequence operations
vector
Cost of overflowing allocated storage
Inserting and erasing elements
deque
Converting between sequences
Cost of overflowing allocated storage
Checked random-access
list
Special list operations
list vs. set
Swapping all basic sequences
Robustness of lists
Performance comparison
set
Eliminating strtok( )
StreamTokenizer: a more flexible solution
A completely reusable tokenizer
stack
queue
Priority queues
Holding bits
bitset<n>
vector<bool>
Associative containers
Generators and fillers for associative containers
The magic of maps
A command-line argument tool
Multimaps and duplicate keys
Multisets
Combining STL containers
Cleaning up containers of pointers
Creating your own containers
Freely-available STL extensions
Non-STL containers
Bitset
Valarray
Summary
Exercises
8: STL Algorithms
Function objects
Classification of function objects
Automatic creation of function objects
Binders
Function pointer adapters
SGI extensions
A catalog of STL algorithms
Support tools for example creation
Filling & generating
Example
Counting
Example
Manipulating sequences
Example
Searching & replacing
Example
Comparing ranges
Example
Removing elements
Example
Sorting and operations on sorted ranges
Sorting
Example
Locating elements in sorted ranges
Example
Merging sorted ranges
Example
Set operations on sorted ranges
Example
Heap operations
Applying an operation to each element in a range
Examples
Numeric algorithms
Example
General utilities
Creating your own STL-style algorithms
Summary
Exercises
Part 3: Advanced Topics
9: Run-time type identification
The “Shape” example
What is RTTI?
Two syntaxes for RTTI
Syntax specifics
typeid( ) with built-in types
Producing the proper type name
Nonpolymorphic types
Casting to intermediate levels
void pointers
Using RTTI with templates
References
Exceptions
Multiple inheritance
Sensible uses for RTTI
Revisiting the trash recycler
Mechanism & overhead of RTTI
Creating your own RTTI
Explicit cast syntax
Summary
Exercises
10: Multiple inheritance
Perspective
Duplicate subobjects
Ambiguous upcasting
virtual base classes
The "most derived" class and virtual base initialization
"Tying off" virtual bases with a default constructor
Overhead
Upcasting
Persistence
MI-based persistence
Improved persistence
Avoiding MI
Mixin types
Repairing an interface
Summary
Exercises
11: Design patterns
The pattern concept
The singleton
Variations on singleton
Classifying patterns
Features, idioms, patterns
Basic complexity hiding
Dynamic aggregation
Factories: encapsulating object creation
Polymorphic factories
Abstract factories
Virtual constructorsBE
Destructor operation
Callbacks
Functor/Command
Strategy
Observer
The “interface” idiom
The “inner class” idiom
The observer example
Multiple dispatching
Visitor, a type of multiple dispatching
Proxy
Efficiency
Reference counting
Flyweight
The composite
Evolving a design: the trash recycler
Improving the design
“Make more objects”
A pattern for prototyping creation
Trash subclasses
Parsing Trash from an external file
Recycling with prototyping
Abstracting usage
Applying double dispatching
Implementing the double dispatch
Applying the visitor pattern
More coupling?
RTTI considered harmful?
Summary
Exercises
A: Recommended reading
C
General C++
My own list of books
Depth & dark corners
The STL
Design Patterns
B: Etc
Index