11 Template metaprogramming

This chapter covers

  • Manipulating types during compilation
  • Usingconstexpr-if to perform branching at compile-time
  • Performing static introspection to check for type properties at compile-time
  • Using std::invoke and std::apply
  • Creating a DSL to define transactions for data record updates

The normal way to think of programming is that we write code, we compile it, and then the user executes the compiled binary. This is the way programming works for the most part.

With C++, we can also write a different kind of program—one that the compiler executes while it compiles our code. This might seem like a strange thing to do (how useful can it be to execute code when we have no input from the user and no data to process?). ...

Get Functional Programming in C++ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.