Why a Metaprogramming Library?





Why a Metaprogramming Library?

Rather than building up metaprograms from scratch, we'll be working with the high-level facilities of the Boost Metaprogramming Library (MPL). Even if you didn't pick up this book to explore the MPL, we think you'll find your investment in learning it to be well worthwhile because of the benefits the MPL can bring to your day-to-day work.

  1. Quality. Most programmers who use template metaprogramming components see themquite properlyas implementation details to be applied toward some greater purpose. By contrast, the MPL authors saw the job of developing useful, high-quality tools and idioms as their central mission. On average, the components in the Boost Metaprogramming Library are more flexible and better implemented than what one would produce along the way to some other goal, and you can expect more optimizations and improvements in the future as updates are released.

  2. Reuse. All libraries encapsulate code in reusable components. More importantly, a well-designed generic library establishes a framework of concepts and idioms that provides a reusable mental model for approaching problems. Just as the C++ Standard Template Library gave us iterators and a function object protocol, the Boost Metaprogramming Library provides type iterators and a metafunction protocol. A well-considered framework of idioms focuses the metaprogrammer's design decisions and enables her to concentrate on the task at hand.

  3. Portability. A good library can smooth over the ugly realities of platform differences. While in theory no C++ metaprogram should be concerned with these issues, in practice support for templates remains inconsistent even six years after standardization. No surprises here: C++ templates are the language's furthest-reaching and most complicated feature, a fact that also accounts for the power of metaprogramming in C++.

  4. Fun. Repeating the same boilerplate code over and over is tedious. Quickly assembling high-level components into readable, elegant designs is fun! The MPL reduces boredom by eliminating the need for the most commonly repeated metaprogramming patterns. In particular, terminating specializations and explicit recursion are often easily and elegantly avoided.

  5. Productivity. Aside from personal gratification, the health of our projects depends on having fun programming. When we stop having fun we get tired, slow, and sloppyand buggy code is even more costly than slowly written code.

As you can see, the Boost Metaprogramming Library is motivated by the same practical considerations that underlie the development of any other library. We think its emergence is a sign that template metaprogramming is finally ready to leave the realm of the esoteric and find a home in the everyday repertoire of working C++ programmers.

Finally, we'd like to emphasize the fourth item above: The MPL not only makes metaprogramming practical and easy, but it's also a great pleasure to work with. We hope that you'll enjoy learning about it as much as we have enjoyed using and developing it.


     Python   SQL   Java   php   Perl 
     game development   web development   internet   *nix   graphics   hardware 
     telecommunications   C++ 
     Flash   Active Directory   Windows