C++ Metastring Library and Its Applications

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.

[1]  Robert Glück,et al.  Generative Programming and Active Libraries , 1998, Generic Programming.

[2]  Bjarne Stroustrup,et al.  The C++ Programming Language: Special Edition , 2000 .

[3]  Zoltan Juhasz,et al.  Implementation of a Finite State Machine with Active Libraries in C++ , 2007, GTTSE.

[4]  Sibylle Schupp,et al.  Generic Programming and High-Performance Libraries , 2004, 18th International Parallel and Distributed Processing Symposium, 2004. Proceedings..

[5]  Ronald L. Rivest,et al.  Introduction to Algorithms , 1990 .

[6]  Neil D. Jones,et al.  An introduction to partial evaluation , 1996, CSUR.

[7]  Robert Glück,et al.  Generative Programming and Active Libraries , 1998, Generic Programming.

[8]  Bjarne Stroustrup,et al.  C++ Programming Language , 1986, IEEE Softw..

[9]  Zoltán Porkoláb,et al.  Debugging C++ template metaprograms , 2006, GPCE '06.

[10]  Yoshihiko Futamura,et al.  Partial Evaluation of Computation Process--An Approach to a Compiler-Compiler , 1999, High. Order Symb. Comput..

[11]  Andrei Alexandrescu,et al.  Modern C++ design: generic programming and design patterns applied , 2001 .

[12]  Todd L. Veldhuizen C++ Templates as Partial Evaluation , 1999, PEPM.

[13]  Dennis Gannon,et al.  Active Libraries: Rethinking the roles of compilers and libraries , 1998, ArXiv.

[14]  Clifford Stein,et al.  Introduction to Algorithms, 2nd edition. , 2001 .

[15]  Joseph Gil,et al.  Simple and safe SQL queries with C++ templates , 2010, Sci. Comput. Program..

[16]  Krzysztof Czarnecki,et al.  Generative programming - methods, tools and applications , 2000 .

[17]  Björn Karlsson,et al.  Beyond the C++ Standard Library , 2005 .

[18]  Donald E. Knuth,et al.  Fast Pattern Matching in Strings , 1977, SIAM J. Comput..

[19]  Robert S. Boyer,et al.  A fast string searching algorithm , 1977, CACM.

[20]  Wei Lu,et al.  C++ reflection for high performance problem solving environments , 2007, SpringSim '07.

[21]  Todd L. Veldhuizen,et al.  Using C++ template metaprograms , 1996 .

[22]  David Abrahams,et al.  C++ Template Metaprogramming: Concepts, Tools, and Techniques from Boost and Beyond (C++ In-Depth Series) , 2004 .

[23]  Jeremy G. Siek,et al.  Concept Checking: Binding Parametric Polymorphism in C++ , 2000 .

[24]  Todd L. Veldhuizen,et al.  Expression templates , 1996 .

[25]  Björn Karlsson,et al.  Beyond the C++ Standard Library: An Introduction to Boost , 2005 .

[26]  Bjarne Stroustrup,et al.  Evolving a language in and for the real world: C++ 1991-2006 , 2007, HOPL.