C++ metastring library and its applications

  • Authors:
  • Zalán Szűgyi;Ábel Sinkovics;Norbert Pataki;Zoltán Porkoláb

  • Affiliations:
  • Department of Programming Languages and Compilers, Eötvös Loránd University, Budapest, Hungary;Department of Programming Languages and Compilers, Eötvös Loránd University, Budapest, Hungary;Department of Programming Languages and Compilers, Eötvös Loránd University, Budapest, Hungary;Department of Programming Languages and Compilers, Eötvös Loránd University, Budapest, Hungary

  • Venue:
  • GTTSE'09 Proceedings of the 3rd international summer school conference on Generative and transformational techniques in software engineering III
  • Year:
  • 2009

Quantified Score

Hi-index 0.00

Visualization

Abstract

C++ template metaprogramming is an emerging direction of generative programming: with proper template definitions we can enforce the C++ compiler to execute algorithms at compilation time. Template metaprograms have become essential part of today's C++ programs of industrial size; they provide code adoptions, various optimizations, DSL embedding, etc. Besides the compilation time algorithms, template metaprogram data-structures are particularly important. From simple typelists to more advanced STL-like data types there are a variety of such constructs. Interesting enough, until recently string, as one of the most widely used data type of programming, has not been supported. Although, boost::mpl::string is an advance in this area, it still lacks the most fundamental string operations. In this paper, we analysed the possibilities of handling string objects at compilation time with a metastring library. We created a C++ template metaprogram library that provides the common string operations, like creating sub-strings, concatenation, replace, and similar. To provide real-life use-cases we implemented two applications on top of our Metastring library. One use case utilizes compilation time inspection of input in the domain of pattern matching algorithms, thus we are able to select the more optimal search method at compilation time. The other use-case implements safePrint, a type-safe version of printf - a widely investigated problem. We present both the performance improvements and extended functionality we have achieved in the applications of our Metastring library.