Skip to content

Book review - C++ Template Metaprogramming



Link: C++ Template Metaprogramming - Concepts, Tools, and Techniques from Boost and Beyond

Template Metaprogramming is a compile-time C++ technique that became extremely popular in the last few years. Before the arrival of this book there was nevertheless no comprehensive source about template programming available. Interested C++ programmers who wanted to read more about this topic were mostly limited to Modern C++ Design (uses template metaprogramming a lot; doesn't explain too much about it though), C++ Templates - The complete guide (dedicates one chapter to template metaprogramming), the source and documentation of the Boost library and some other, minor sources. David Abrahams and Aleksey Gurtovoy attempted to fill this void and they've been succesful.

The 350 pages of the book are divided into 11 chapters and a surprisingly large appendix (60+ pages). More important than this official structure is a second, non-official structure which divides the book into two parts though, a theoretical and a practical part.

The first part, containing chapters 1 to 7/8, lays the theoretical foundations necessary for the reader to understand template metaprogramming. The authors introduce the libraries Boost::MPL (the main topic of the first few chapters), Boost::Lambda and explain the how these libraries were implemented and how to use them when writing your own template metaprogramming code.
Reading the first part was partly awesome and partly tedious, depending on what exactly was discussed. While reading I often wondered whether the level of detail the authors present is necessary or if they should have opted for a more general presentation of the material in some cases. In fact I didn't manage to finish reading the book at my first attempt. The material was often too theoretical and not what I had hoped to learn. I acknowledge that this is of course a problem with me, not with the book.

Luckily I gave the book a second try or otherwise I would have never seen the second part (chapters 8/9 - 11). The second part is the practical application of the theoretical concepts introduced in the first part. The focus is on domain-specific embedded languages (DSEL). In the context of C++ Template metaprogramming these are little sub-languages built from C++ language features that allow the transfer of a problem from it's natural representation to C++ code. In chapter 10 some existing DSELs are introduced, their advantages and implementations are explained. Chapter 11 walks the reader through the creation of a new DSEL.

All in all I'd suggest this book to intermediate to advanced C++ programmers. Even though the first part was often too dry for my tastes the second part is worth every cent spent on the book. The only problem I still have is that I don't regularly work with any DSELs I could transfer to C++ metaprograms to make my work easier. But should I ever need to do that I will definitely take the Abrahams/Gurtovoy book out of my bookshelf again.

Trackbacks

Programming stuff on : Template meta-programming in D

Show preview
I wrote about template meta-programming in C++ before. Today I checked out the D programming language which allows template meta-programming too. Template meta-programming in D seems to be way superior to template meta-programming in C++. One major adv

Comments

Display comments as Linear | Threaded

No comments

Add Comment

Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.
Standard emoticons like :-) and ;-) are converted to images.
BBCode format allowed
Form options

Submitted comments will be subject to moderation before being displayed.