BoostCon 2012

Template Metaprogramming

Template Metaprogramming allows the construction of libraries that “think they’re compilers,” [1] i.e. libraries that generate code. That in turn enables users to code in terms of declarative specification rather than by cobbling together general-purpose procedural elements. Think of it as a power tool that a library writer can use to raise the level of abstraction he provides.

Boost.MPL is a framework of compile-time algorithms, sequences and metafunctions that brings the practical application of C++ template metaprogramming within reach of programmers in the real world. By combining higher-order abstractions, analogies to familiar STL concepts, and workarounds for the most problematic compilers, developers are able to directly express their intention rather than thinking about the low-level details of the C++ template system. The MPL has been extensively stress-tested in the implementations of other existing Boost libraries, and has been tuned for compile-time performance and ability to handle large metaprograms.

For example:

Spirit is a flexible parser generation framework in which the grammars themselves are written in pure C++. By approximating Extended Backus-Normal Form (EBNF) with C++ operators, Spirit demolishes the barrier found in most parsing systems between the grammar and semantic actions, making it simple to add small, lightweight parsers to any program. Combined with a modular design, the use of advanced template metaprogramming, and infinite lookahead, Spirit scales smoothly to handle the most difficult parsing problems. Since the parser compiles directly to machine code without lookup tables or driver programs, the result is amazingly tight and fast. Unlike traditional parser generators, Spirit doesn’t stop with parsing and semantic actions: it also gives you a suite of built-in grammars for common patterns, and associated parsing tools such as symbol tables and AST generators.

[1] Todd Veldhuizen, Blitz++: The library that thinks it is a compiler (SciTools 98)

News

  • The Future of C++

    Dave Abrahams has been thinking about what’s next for the C++ language in a series of articles at the C++Next blog.

    More...

  • Programmer’s Grimoire Interview: now in English

    Thanks to Takatoshi Kondo and colleagues, non-Japanese readers can now view this excerpt from Volume 2, “The Evolution of Languages” - Programmer’s Grimoire Interview with Dave Abrahams  

    More...

  • The latest issue of Programmer’s Grimoire features an interview with Dave Abrahams

    Vol.2 of the Japanese-language journal Programmer’s Grimoire, is subtitled “The Evolution of Languages.” If you don’t read Japanese, fear not, an English translation is coming soon.

    More...