Functional programming with C++ template metaprograms

  • Authors:
  • Zoltán Porkoláb

  • Affiliations:
  • Eötvös Loránd University, Faculty of Informatics, Dept. of Programming Languages and Compilers, Budapest, Hungary

  • Venue:
  • CEFP'09 Proceedings of the Third summer school conference on Central European functional programming school
  • Year:
  • 2009

Quantified Score

Hi-index 0.00

Visualization

Abstract

Template metaprogramming is an emerging new direction of generative programming. With the clever definitions of templates we can force the C++ compiler to execute algorithms at compilation time. Among the application areas of template metaprograms are the expression templates, static interface checking, code optimization with adaption, language embedding and active libraries. However, as template metaprogramming was not an original design goal, the C++ language is not capable of elegant expression of metaprograms. The complicated syntax leads to the creation of code that is hard to write, understand and maintain. Although template metaprogramming has a strong relationship with functional programming, this is not reflected in the language syntax and existing libraries. In this paper we give a short and incomplete introduction to C++ templates and the basics of template metaprogramming. We will enlight the role of template metaprograms, and some important and widely used idioms. We give an overview of the possible application areas as well as debugging and profiling techniques. We suggest a pure functional style programming interface for C++ template metaprograms in the form of embedded Haskell code which is transformed to standard compliant C++ source.