May 2015
Intermediate to advanced
572 pages
9h 52m
English
CHAPTER 3
![]()
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 ...