C++ Template Metaprogramming sheds light on the most powerful idioms of today's C++, at long last delivering practical metaprogramming tools and techniques into the hands of the everyday programmer.
Chapter 1. Introduction
Section 1.1. Getting Started
Section 1.2. So What's a Metaprogram?
Section 1.3. Metaprogramming in the Host Language
Section 1.4. Metaprogramming in C++
Section 1.5. Why Metaprogramming?
Section 1.6. When Metaprogramming?
Section 1.7. Why a Metaprogramming Library?
Chapter 2. Traits and Type Manipulation
Section 2.1. Type Associations
Section 2.2. Metafunctions
Section 2.3. Numerical Metafunctions
Section 2.4. Making Choices at Compile Time
Section 2.5. A Brief Tour of the Boost Type Traits Library
Section 2.6. Nullary Metafunctions
Section 2.7. Metafunction Definition
Section 2.8. History
Section 2.9. Details
Section 2.10. Exercises
Chapter 3. A Deeper Look at Metafunctions
Section 3.1. Dimensional Analysis
Section 3.2. Higher-Order Metafunctions
Section 3.3. Handling Placeholders
Section 3.4. More Lambda Capabilities
Section 3.5. Lambda Details
Section 3.6. Details
Section 3.7. Exercises
Chapter 4. Integral Type Wrappers and Operations
Section 4.1. Boolean Wrappers and Operations
Section 4.2. Integer Wrappers and Operations
Section 4.3. Exercises
Chapter 5. Sequences and Iterators
Section 5.1. Concepts
Section 5.2. Sequences and Algorithms
Section 5.3. Iterators
Section 5.4. Iterator Concepts
Section 5.5. Sequence Concepts
Section 5.6. Sequence Equality
Section 5.7. Intrinsic Sequence Operations
Section 5.8. Sequence Classes
Section 5.9. Integral Sequence Wrappers
Section 5.10. Sequence Derivation
Section 5.11. Writing Your Own Sequence
Section 5.12. Details
Section 5.13. Exercises
Chapter 6. Algorithms
Section 6.1. Algorithms, Idioms, Reuse, and Abstraction
Section 6.2. Algorithms in the MPL
Section 6.3. Inserters
Section 6.4. Fundamental Sequence Algorithms
Section 6.5. Querying Algorithms
Section 6.6. Sequence Building Algorithms
Section 6.7. Writing Your Own Algorithms
Section 6.8. Details
Section 6.9. Exercises
Chapter 7. Views and Iterator Adaptors
Section 7.1. A Few Examples
Section 7.2. View Concept
Section 7.3. Iterator Adaptors
Section 7.4. Writing Your Own View
Section 7.5. History
Section 7.6. Exercises
Chapter 8. Diagnostics
Section 8.1. Debugging the Error Novel
Section 8.2. Using Tools for Diagnostic Analysis
Section 8.3. Intentional Diagnostic Generation
Section 8.4. History
Section 8.5. Details
Section 8.6. Exercises
Chapter 9. Crossing the Compile-Time/Runtime Boundary
Section 9.1. for_each
Section 9.2. Implementation Selection
Section 9.3. Object Generators
Section 9.4. Structure Selection
Section 9.5. Class Composition
Section 9.6. (Member) Function Pointers as Template Arguments
Section 9.7. Type Erasure
Section 9.8. The Curiously Recurring Template Pattern
Section 9.9. Explicitly Managing the Overload Set
Section 9.10. The "sizeof Trick"
Section 9.11. Summary
Section 9.12. Exercises
Chapter 10. Domain-Specific Embedded Languages
Section 10.1. A Little Language ...
Section 10.2. ... Goes a Long Way
Section 10.3. DSLs, Inside Out
Section 10.4. C++ as the Host Language
Section 10.5. Blitz++ and Expression Templates
Section 10.6. General-Purpose DSELs
Section 10.7. The Boost Spirit Library
Section 10.8. Summary
Section 10.9. Exercises
Chapter 11. A DSEL Design Walkthrough
Section 11.1. Finite State Machines
Section 11.2. Framework Design Goals
Section 11.3. Framework Interface Basics
Section 11.4. Choosing a DSL
Section 11.5. Implementation
Section 11.6. Analysis
Section 11.7. Language Directions
Section 11.8. Exercises
Appendix A. An Introduction to Preprocessor Metaprogramming
Section A.1. Motivation
Section A.2. Fundamental Abstractions of the Preprocessor
Section A.3. Preprocessor Library Structure
Section A.4. Preprocessor Library Abstractions
Section A.5. Exercise
Appendix B. The typename and template Keywords
Section B.1. The Issue
Section B.2. The Rules
Appendix C. Compile-Time Performance
Section C.1. The Computational Model
Section C.2. Managing Compilation Time
Section C.3. The Tests
Appendix D. MPL Portability Summary
A metaprogram is a program that generates or manipulates program code. Ever since generic programming was introduced to C++, programmers have discovered myriad "template tricks" for manipulating programs as they are compiled, effectively eliminating the barrier between program and metaprogram. While excitement among C++ experts about these capabilities has reached the community at large, their practical application remains out of reach for most programmers. This book explains what metaprogramming is and how it is best used. It provides the foundation you'll need to use the template metaprogramming effectively in your own work.
This book is aimed at any programmer who is comfortable with idioms of the Standard Template Library (STL). C++ power-users will gain a new insight into their existing work and a new fluency in the domain of metaprogramming. Intermediate-level programmers who have learned a few advanced template techniques will see where these tricks fit in the big picture and will gain the conceptual foundation to use them with discipline. Programmers who have caught the scent of metaprogramming, but for whom it is still mysterious, will finally gain a clear understanding of how, when, and why it works. All readers will leave with a new tool of unprecedented power at their disposal-the Boost Metaprogramming Library.
The companion CD-ROM contains all Boost C++ libraries, including the Boost Metaprogramming Library and its reference documentation, along with all of the book's sample code and extensive supplementary material.