0%

Book Description

To say that C++ programmers embrace metaprogramming is a real stretch. Outright rejection is probably more accurate. And yet, C++ template metaprogramming is ideal for performing automatic compile-time optimization. With this example-driven ebook, you’ll learn how improved metaprogramming techniques in C++11 and C++14 can help you avoid a lot of mistakes and tedious work by making the compiler work for you.

Authors Edouard Alligand and Joel Falcou show you how the process works and what it takes to build and apply a basic metaprogramming toolbox. Then comes the real payoff: you’ll learn about a set of existing metaprogramming techniques you can use to perform fast and precise metaprogramming tasks without error—including the Boost.MPL, Boost.Hana, and Brigand libraries.

  • Understand basic metaprogramming concepts: programs whose input and output are programs themselves
  • Learn how metaprogramming principles can help make your code more compact, generic, elegant, and less error-prone
  • Explore how features in C++11 and C++14 make the design of metaprograms easier
  • Improve performance, reduce maintenance, and test less often

Table of Contents

  1. Preface
    1. A Journey of a Thousand Miles Begins with a Single Step
    2. Understanding Metaprogramming
    3. Conventions Used in This Report
    4. Acknowledgments
  2. 1. Introduction
    1. A Misunderstood Technique
    2. What Is Metaprogramming?
      1. The Early History of Metaprogramming
      2. Enter C++ Templates
    3. How to Get Started with Metaprogramming
      1. Checking Integer Type
      2. Checking the Memory Model
    4. Summary
  3. 2. C++ Metaprogramming in Practice
    1. A Typical Code Maintenance Assignment
    2. Creating a Straightforward Interface
    3. Generating Code Automatically
    4. Making Values and Pointers Work Together
      1. Type Manipulation 101
      2. A Generic Function Translator
      3. Extracting the C Function’s Parameters
      4. Getting a List of Functions and Parameters
      5. Filling the Values for the C Function
      6. Calling the Legacy C Function
      7. Simplifying the Code
    5. Putting It All Together
    6. Summary
  4. 3. C++ Metaprogramming and Application Design
    1. Compile-Time Versus Runtime Paradigms
      1. Values at Compile Time
      2. Functions at Compile Time
    2. Type Containers
    3. Compile-Time Operations
      1. Using Pack-Intrinsic Information
      2. Adding and Removing Pack Elements
      3. Pack Rewrapping
      4. Container Transformations
    4. Advanced Uses of Metaprogramming
      1. A Revisited Command Pattern
      2. Compile-Time Serialization
    5. Helper Functions and Libraries
    6. Summary