C++ Templates: The Complete Guide Customer Reviews: 2 Average Customer Rating:      Write a Review and tell the world about this title! People who purchase this book frequently purchase: - Modern C++ Design; Andrei Alexandrescu, $46.50, 22% Off!
- Effective C++: 55 Specific Ways to Improve Your Programs and Designs, 3rd Edition; Scott Meyers, $38.95, 22% Off!
- C++ Template Metaprogramming: Concepts, Tools, and Techniques from Boost and Beyond; David Abrahams, et al, $38.95, 22% Off!
- The C++ Standard Library: A Tutorial and Reference; Nicolai M. Josuttis, $57.95, 23% Off!
Books on similar topics, in best-seller order:Books from the same publisher, in best-seller order:
Templates are among the most powerful features of C++, but they are too often
neglected, misunderstood, and misused. C++ Templates: The Complete Guide
provides software architects and engineers with a clear understanding of why,
when, and how to use templates to build and maintain cleaner, faster, and smarter
software more efficiently.
C++ Templates begins with an insightful tutorial on basic concepts
and language features. The remainder of the book serves as a comprehensive reference,
focusing first on language details, then on a wide range of coding techniques,
and finally on advanced applications for templates. Examples used throughout
the book illustrate abstract concepts and to demonstrate best practices.
Readers learn:
- The exact behaviors of templates
- How to avoid the pitfalls associated with templates
- Idioms and techniques from the basic to the previously undocumented
- How to reuse source code without threatening performance or safety
- How to increase the efficiency of C++ programs
- How to produce more flexible and maintainable software
This practical guide shows programmers how to exploit the full power of the
template features in C++.
Table of Contents
Preface.
Acknowledgments.
1. About this Book.
What You Should Know Before Reading this Book.
Overall Structure of the Book.
How to Read this Book.
Some Remarks About Programming Style.
The Standard vs. Reality.
Example Code and Additional Information.
Feedback.
I. THE BASICS.
2. Why Templates?
3. Function Templates.
A First Look at Function Templates.
Defining the Template.
Using the Template.
Argument Deduction.
Template Parameters.
Overloading Function Templates.
Summary.
4. Class Templates.
Implementation of Class Template Stack.
Declaration of Class Templates.
Implementation of Member Functions.
Usage of Class Template Stack.
Specializations of Class Templates.
Partial Specialization.
Default Template Parameters.
Summary.
5. Nontype Template Parameters.
Nontype Class Template Parameters.
Nontype Function Template Parameters.
Restrictions for Nontype Template Parameters.
Summary.
6. Tricky Basics.
Keyword typename.
The .template Construct.
Using this-
Member Templates.
Template Template Parameters.
Template Template Argument Matching.
Zero Initialization.
Summary.
7. Using Templates in Practice.
The Inclusion Model.
Linker Errors.
The Inclusion Mode.
Explicit Instantiation.
Example of Explicit Instantiation.
Combining the Inclusion Model and Explicit Instantiation.
Exporting Templates.
The Keyword export.
Limitations of the Separation Model.
Preparing for the Separation Model.
Templates and inline.
Precompiled Headers.
Debugging Templates.
Decoding the Error Novel.
Shallow Instantiation.
Long Symbols.
Tracers.
Oracles.
Archetypes.
Afternotes.
Summary.
8. Basic Template Terminology.
“Class Template” or “Template
Class” ?
Instantiation and Specialization.
Declarations versus Definitions.
The One Definition Rule.
Template Arguments versus Template Parameters.
II. TEMPLATES IN DEPTH.
9. Fundamentals In Depth.
Parameterized Declarations.
Virtual Member Functions.
Linkage Of Templates.
Primary Templates.
Template Parameters.
Template Type Parameters.
Template Nontype Parameters.
Template Template Parameters.
Default Template Arguments.
Template Arguments.
Function Template Arguments.
Template Type Arguments.
Template Nontype Arguments.
Template Template Arguments.
Equivalence.
Friends.
Friend Functions.
Friend Templates.
10. Names in Templates.
Name Taxonomy.
Looking Up Names.
Argument-Dependent Lookup.
Friend Name Injection.
Injected Class Names.
Parsing Templates.
Context Sensitivity in Nontemplates.
Dependent Names of Types.
Dependent Names of Templates.
Dependent Names in Using-Declarations.
Derivation and Class Templates.
Nondependent Base Classes.
Dependent Base Classes.
Afternotes.
11. Instantiation.
On-Demand Instantiation.
Lazy Instantiation.
The C++ Instantiation Model.
Two-Stage Lookup.
Points of Instantiation.
The Inclusion and Separation Models.
Looking Across Translation Units.
Examples.
Implementation Schemes.
Greedy Instantiation.
Queried Instantiation.
Iterated Instantiation.
Explicit Instantiation.
Purpose and Limitations.
Afternotes.
12. Function Template Argument Deduction.
Deduction Process.
Deduced Contexts.
Special Deduction Situations.
Allowable Argument Conversions.
Class Template Parameters.
Default Call Arguments.
Avoiding Deduction: The Barton-Nackman Trick.
Afternotes.
13. Specialization and Overloading.
When “Generic Code” Doesn't Quite
Cut It.
Transparent Customization.
Semantic Transparency.
Overloading Function Templates.
Signatures.
Partial Ordering of Overloaded Function Templates.
Formal Ordering Rules.
Templates and Nontemplates.
Explicit Specialization.
Full Class Template Specialization.
Full Function Template Specialization.
Full Member Specialization.
Partial Class Template Specialization.
Afternotes.
14. Future Directions.
The Angle Bracket Hack.
Relaxed typename Rules.
Default Function Template Arguments.
String Literal and Floating-Point Template Arguments.
Relaxed Matching Of Template Template Parameters.
Typedef Templates.
Partial Specialization of Function Templates.
The typeof Operator.
Named Template Arguments.
Static Properties.
Custom Instantiation Diagnostics.
Overloaded Class Templates.
List Parameters.
Layout Control.
Initializer Deduction.
Function Expressions.
III. Templates and Design.
15. The Polymorphic Power Of Templates.
Dynamic Polymorphism.
Static Polymorphism.
Dynamic versus Static Polymorphism.
Combining both Forms.
New Forms of Design Patterns.
Generic Programming.
Afternotes.
16. Traits and Policy Classes.
An Example: Accumulating A Sequence.
Fixed Traits.
Value Traits.
Parameterized Traits.
Policies and Policy Classes.
Traits and Policies: What's The Difference?
Member Templates vs. Template Template Parameters.
Combining Multiple Policies and/or Traits.
Accumulation with General Iterators.
Type Functions.
References and Qualifiers.
Type Classification.
Determining Fundamental Types.
Enumeration Classification With Overload Resolution.
Determining Compound Types.
Identifying Function Types.
Determining Class Types.
Putting it all Together.
Promotion Traits.
Policy Traits.
Read-only Parameter Types.
Copying, Swapping and Moving.
Afternotes.
17. Templates and Inheritance.
Named Template Arguments.
The Empty Base Class Optimization (EBCO).
Layout Principles.
Members as Bases.
The Curiously Recurring Template Pattern (CRTP).
Parameterized Virtuality.
Afternotes.
18. Metaprograms.
A First Example of a Metaprogram.
Enumeration Values versus Static Constants.
A Second Example: Processing the Square Root.
Tracking All Instantiations.
Using Induction Variables.
Computational Completeness.
Recursive Instantiation vs. Recursive Template Arguments.
Using Metaprograms to Unroll Loops.
Expression Templates.
Temporaries and Split Loops.
Encoding Expressions in Template Arguments.
Performance and Limitations of Expression Templates.
Afternotes.
IV. Advanced Applications.
19. Smart Pointers.
Holders and Trules.
Protecting Against Exceptions.
Holders.
Holders as Members.
Resource Acquisition is Initialization.
Holder Limitations.
Copying Holders.
Copying Holders Across Function Calls.
Trules.
Reference Counting.
Where Is The Counter?
Concurrent Counter Access.
Destruction and Deallocation.
The CountingPtr Template.
A Simple Non-Intrusive Counter.
A Simple Intrusive Counter Template.
Constness.
Implicit Conversions.
Comparisons.
Afternotes.
20. Tuples.
Duos.
Recursive Duos.
Number of Fields.
Type of Fields.
Value of Fields.
Tuple Construction.
Afternotes.
21. Function Objects and Callbacks.
Direct, Indirect, and Inlined Calls.
Pointers and References to Functions.
Pointer to Member Functions.
Class Type Functors.
A First Example of Class Type Functors.
Type of Class Type Functors.
Specifying Functors.
Functors as Template Type Arguments.
Functors as Function Call Arguments.
Combining Function Call Parameters and Template Type Parameters.
Functors as Template Nontype Arguments.
Function Pointer Encapsulation.
Introspection.
Analyzing A Functor Type.
Accessing Parameter Types.
Encapsulating Function Pointers.
Composition.
Simple Composition.
Mixed Type Composition.
Reducing the Number of Parameters.
Value Binders.
Selecting the Binding.
Bound Signature.
Argument Selection.
Convenience Functions.
Afternotes.
APPENDIX.
A: The One Definition Rule.
Translation Units.
Declarations and Definitions.
One Definition Rule.
One-Per-Program Constraints.
One-Per-Translation Unit Constraints.
Cross-Translation Unit Equivalence Constraints.
B: Overload Resolution.
When does Overload Resolution Kick in?
Simplified Overload Resolution.
The Implied Argument For Member Functions.
Refining The Perfect Match.
Overloading Details.
Prefer Nontemplates.
Conversion Sequences.
Pointer Conversions.
Functors And Surrogate Functions.
Other Overloading Contexts.
C: Resources.
Newsgroups.
Books and Websites.
Book Recommendations.
Glossary.
Index
Customer Reviews
Customer Reviews: 2 Average Customer Rating:      Feb 17, 2004     A review from State College Pennsylvania Excellent Introductory and Intermediate Template Guide This is one of the most well written text books I have ever read. It is an easy read, and it conveys the most complicated ideas about templates in a manner that any beginner can understand. This introductory-to-intermediate text provides a strong foundation for understanding the more complex features of C++ templates from such books as "Modern C++ Design" by Alexandrescu.
Jan 20, 2004     Sarir from Tucson, AZ, USA The title says it all. There may not be much competition for C++ template books, but this one is well organized, has great examples, and is quite thorough. It has everything you've always wanted to know about templates and might even make you sorry you asked. :-)
I highly recommend it to anyone learning about templates.
|