Book description
Templates are among the most powerful features of C++, but they remain misunderstood and underutilized, even as the C++ language and development community have advanced. In C++ Templates, Second Edition, three pioneering C++ experts show why, when, and how to use modern templates to build software that’s cleaner, faster, more efficient, and easier to maintain.
Now extensively updated for the C++11, C++14, and C++17 standards, this new edition presents state-of-the-art techniques for a wider spectrum of applications. The authors provide authoritative explanations of all new language features that either improve templates or interact with them, including variadic templates, generic lambdas, class template argument deduction, compile-time if, forwarding references, and user-defined literals. They also deeply delve into fundamental language concepts (like value categories) and fully cover all standard type traits.
The book starts with an insightful tutorial on basic concepts and relevant language features. The remainder of the book serves as a comprehensive reference, focusing first on language details and then on coding techniques, advanced applications, and sophisticated idioms. Throughout, examples clearly illustrate abstract concepts and demonstrate best practices for exploiting all that C++ templates can do.
- Understand exactly how templates behave, and avoid common pitfalls
- Use templates to write more efficient, flexible, and maintainable software
- Master today’s most effective idioms and techniques
- Reuse source code without compromising performance or safety
- Benefit from utilities for generic programming in the C++ Standard Library
- Preview the upcoming concepts feature
The companion website, tmplbook.com, contains sample code and additional updates.
Table of contents
- Cover Page
- Title Page
- Copyright Page
- Dedication
- Contents
- Preface
- Acknowledgments for the Second Edition
- Acknowledgments for the First Edition
- About This Book
-
Part I: The Basics
- 1 Function Templates
-
2 Class Templates
- 2.1 Implementation of Class Template Stack
- 2.2 Use of Class Template Stack
- 2.3 Partial Usage of Class Templates
- 2.4 Friends
- 2.5 Specializations of Class Templates
- 2.6 Partial Specialization
- 2.7 Default Class Template Arguments
- 2.8 Type Aliases
- 2.9 Class Template Argument Deduction
- 2.10 Templatized Aggregates
- 2.11 Summary
- 3 Nontype Template Parameters
- 4 Variadic Templates
- 5 Tricky Basics
- 6 Move Semantics and enable_if<>
- 7 By Value or by Reference?
- 8 Compile-Time Programming
- 9 Using Templates in Practice
- 10 Basic Template Terminology
- 11 Generic Libraries
-
Part II: Templates in Depth
- 12 Fundamentals in Depth
- 13 Names in Templates
- 14 Instantiation
-
15 Template Argument Deduction
- 15.1 The Deduction Process
- 15.2 Deduced Contexts
- 15.3 Special Deduction Situations
- 15.4 Initializer Lists
- 15.5 Parameter Packs
- 15.6 Rvalue References
- 15.7 SFINAE (Substitution Failure Is Not An Error)
- 15.8 Limitations of Deduction
- 15.9 Explicit Function Template Arguments
- 15.10 Deduction from Initializers and Expressions
- 15.11 Alias Templates
- 15.12 Class Template Argument Deduction
- 15.13 Afternotes
- 16 Specialization and Overloading
-
17 Future Directions
- 17.1 Relaxed typename Rules
- 17.2 Generalized Nontype Template Parameters
- 17.3 Partial Specialization of Function Templates
- 17.4 Named Template Arguments
- 17.5 Overloaded Class Templates
- 17.6 Deduction for Nonfinal Pack Expansions
- 17.7 Regularization of void
- 17.8 Type Checking for Templates
- 17.9 Reflective Metaprogramming
- 17.10 Pack Facilities
- 17.11 Modules
-
Part III: Templates and Design
- 18 The Polymorphic Power of Templates
- 19 Implementing Traits
- 20 Overloading on Type Properties
- 21 Templates and Inheritance
- 22 Bridging Static and Dynamic Polymorphism
- 23 Metaprogramming
- 24 Typelists
- 25 Tuples
- 26 Discriminated Unions
- 27 Expression Templates
- 28 Debugging Templates
-
Appendixes
- A The One-Definition Rule
- B Value Categories
- C Overload Resolution
- D Standard Type Utilities
- E Concepts
- Bibliography
- Glossary
- Index
Product information
- Title: C++ Templates: The Complete Guide, 2nd Edition
- Author(s):
- Release date: September 2017
- Publisher(s): Addison-Wesley Professional
- ISBN: 9780134778808
You might also like
book
A Tour of C++, 3rd Edition
In A Tour of C++, Third Edition, Bjarne Stroustrup provides an overview of ISO C++, C++20, …
book
A Tour of C++, 2nd Edition
In Bjarne Stroustrup, the creator of C++, describes what constitutes modern C++. This concise, self-contained guide …
book
C++ Standard Library, The: A Tutorial and Reference, 2nd Edition
The Best-Selling C++ Resource Now Updated for C++11 The C++ standard library provides a set of …
book
The C++ Programming Language, 4th Edition
The new C++11 standard allows programmers to express ideas more clearly, simply, and directly, and to …