Advanced C++ Metaprogramming
Davide Di Gennaro
C++ metaprogramming is something that many people skip or avoid as most complicated part of the language. In fact it should be one of most important reasons to still use C++ today – not many languages have such an advanced solution for compile-time, static-typed computations. Current version of C++ (in 2015) has still some limits in template handling – but you can write solutions that ignore them and push the language to it’s limits. The book is full of “make something unreal” tips which you can use in your new data structure or algorithm implementation. Inside the book you will find explanations of some popular C++ idioms like SFINAE, S.C.A.R.Y initialization, tagging or type traits.
Which parts I found most useful? There is no such a part. Whole book, from first to last page is important and I would have problems finding parts which could be omitted. This is because the author does not use long descriptions like for example Scott Meyers. He just shows the code examples and provides necessary explanations. Maybe you can skip some of the topics if you are not interested now in them – but in the same time they can present tips that could be useful when applied to something different.
In summary, I will have to read this book again in the future – the tricks it contains are so specific that you can easy forget them, but still, when you read it, you feel it is something you will need. There is also third edition published by Apress that probably is rewritten as the author writes at his blog (see below) that at least one chapter could be written better. You need to remember that some of these solutions can be now obsolete in the presence of C++11 new additions (static_assert, enable_if), but most of the book is still valid today.
What you will learn
Anything you afraid to ask about C++ template programming. Lots of language-specific tricks that can be used for compile-time calculations, type information building and data structure definition.
Table of contents
Small Object Toolkit
Opaque Type Principle
Appendix A: Exercises
Appendix B: Bibliography
If you have a need to push the limits of C++ templates, this book will open few doors for you. I recommend buying third edition or later to avoid mistakes.
Book home page: Advanced C++ Metaprogramming – erratas
* very useful & long list of C++ template tricks
* follows well-known idioms
* code descriptions cut to minimal
* can be little outdated in the presence of C++11/14 (but not too much)