Template Metaprogramming - Benefits and Drawbacks of Template Metaprogramming

Benefits and Drawbacks of Template Metaprogramming

Compile-time versus execution-time tradeoff
If a great deal of template metaprogramming is used, compilation may become slow; section 14.7.1 of the current standard defines the circumstances under which templates are implicitly instantiated. As with most aspects of C++, you pay only for what you use: defining a template does not imply that it will be instantiated, and instantiating a class template does not cause its member definitions to be instantiated. Depending on the style of use, templates may compile either faster or slower than hand-rolled code.
Generic programming
Template metaprogramming allows the programmer to focus on architecture and delegate to the compiler the generation of any implementation required by client code. Thus, template metaprogramming can accomplish truly generic code, facilitating code minimization and better maintainability.
Readability
With respect to C++, the syntax and idioms of template metaprogramming are esoteric compared to conventional C++ programming, and template metaprograms can be very difficult to understand. Metaprograms can thus be difficult to maintain by programmers inexperienced in template metaprogramming (though this may vary with the language's implementation of template metaprogramming syntax). On the other hand, template metaprogramming can often be used to make programs much shorter and simpler, and thus more readable.

Read more about this topic:  Template Metaprogramming

Famous quotes containing the words benefits and/or drawbacks:

    I do seriously believe that if we can measure among the States the benefits resulting from the preservation of the Union, the rebellious States have the larger share. It destroyed an institution that was their destruction. It opened the way for a commercial life that, if they will only embrace it and face the light, means to them a development that shall rival the best attainments of the greatest of our States.
    Benjamin Harrison (1833–1901)

    France has neither winter nor summer nor morals—apart from these drawbacks it is a fine country.
    Mark Twain [Samuel Langhorne Clemens] (1835–1910)