O'Reilly logo

Advanced Metaprogramming in Classic C++ by Davide Di Gennaro

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

CHAPTER 2

image

Small Object Toolkit

The previous chapter focused on the connection between template programming and style. In short, templates are elegant, as they allow you to write efficient code that looks simple because they hide the underlying complexity.

If you recall the introductory example of sq from Chapter 1, it’s clear that the first problem of TMP is choosing the best C++ entity that models a concept and makes the code look clear at the point of instantiation.

Most classic functions use internally temporary variables and return a result. Temporary variables are cheap, so you must give the intermediate results a name to increase the readability ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required