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 3

image

Static Programming

Templates are exceptionally good at forcing the compiler and optimizer to perform some work only when the executable program is generated. By definition, this is called static work. This is as opposed to dynamic work, which refers to what is done when the program runs.

Some activities must be completed before runtime (computing integer constants) and some activities have an impact on runtime (generating machine code for a function template, which is later executed).

TMP can produce two types of code—metafunctions, which are entirely static (for example, a metafunction unsigned_integer<N>::type that returns an integer ...

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