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.
Supported by TÁMOP-4.2.1/B-09/1/KMR-2010-0003.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Preview
Unable to display preview. Download preview PDF.
References
Alexandrescu, A.: Modern C++ Design: Generic Programming and Design Patterns Applied. Addison-Wesley, Reading (2001)
Abrahams, D., Gurtovoy, A.: C++ Template Metaprogramming: Concepts, Tools, and Techniques from Boost and Beyond. Addison-Wesley, Reading (2004)
Boyer, R.S., Moore, J.S.: A Fast String Searching Algorithm. Communication of the ACM 20, 762–772 (1977)
Cormen, T.H., Leiserson, C.E., Rivest, R.L., Stein, C.: Introduction to Algorithms. The MIT Press, Cambridge (2001)
Czarnecki, K., Eisenecker, U.W.: Generative Programming: Methods, Tools and Applications. Addison-Wesley, Reading (2000)
Czarnecki, K., Eisenecker, U.W., Glück, R., Vandevoorde, D., Veldhuizen, T.L.: Generative Programming and Active Libraries. Springer, Heidelberg (2000)
Devadithya, T., Chiu, K., Lu, W.: C++ Reflection for High Performance Problem Solving Environments. In: Proceedings of the 2007 Spring Simulation Multiconference, vol. 2, pp. 435–440 (2007)
Futamura, Y.: Partial Evaluation of Computation Process – An approach to a Compiler-Compiler. Systems, Computers, Controls 2(5), 45–50; Reprinted in Higher-Order and Symbolic Computation 12(4), 381–391 (1999), with a foreword. Kluwer Academic Publishers (2000)
Gil, J.(Y.), Lenz, K.: Simple and safe SQL queries with c++ templates. In: Proc. of Generative And Component Engineering 2007, The ACM Digital Library, pp. 13–24 (2007)
Gregor, D., Järvi, J., Powell, G.: Variadic Templates (Revision 3). Number N2080=06-0150, ANSI/ISO C++ Standard Committee (October 2006)
Gregor, D., Järvi, J., Kulkarni, M., Lumsdaine, A., Musser, D., Schupp, S.: Generic programming and high-performance libraries. International Journal of Parallel Programing 33(2), 145–164 (2005)
Jones, N.D.: An introduction to partial evaluation. ACM Computing Surveys 28(3), 480–503 (1996)
Juhász, Z., Sipos, Á., Porkoláb, Z.: Implementation of a Finite State Machine with Active Libraries in C++. In: Lämmel, R., Visser, J., Saraiva, J. (eds.) GTTSE 2007. LNCS, vol. 5235, pp. 474–488. Springer, Heidelberg (2008) ISBN 978-3-540-88642-6
Karlsson, B.: Beyond the C++ Standard Library, An Introduction to Boost. Addison-Wesley, Reading (2005)
Knuth, D.E., Morris Jr., J.H., Pratt, V.R.: Fast Pattern Matching in Strings. SIAM J. Comput. 6(2), 323–350 (1977)
Meyers, S.: Effective STL. Addison-Wesley, Reading (2001)
Porkoláb, Z., Mihalicza, J., Sipos, Á.: Debugging C++ Template Metaprograms. In: Proc. of Generative Programming and Component Engineering (GPCE 2006), The ACM Digital Library, pp. 255–264 (2006)
ANSI/ISO C++ Committee. Programming Languages – C++. ISO/IEC 14882:1998(E). American National Standards Institute (1998)
Siek, J., Lumsdaine, A.: Concept checking: Binding parametric polymorphism in C++. In: First Workshop on C++ Template Metaprogramming (October 2000)
Sipos, Á., Porkoláb, Z., Pataki, N., Zsók, V.: Meta < Fun> - Towards a Functional-Style Interface for C++ Template Metaprograms. In: Proceedings of 19th International Symposium of Implementation and Application of Functional Languages (IFL 2007), pp. 489–502 (2007)
Stroustrup, B.: Evolving a language in and for the real world: C++ 1991-2006. ACM HOPL-III (June 2007)
Stroustrup, B.: The C++ Programming Language Special Edition. Addison- Wesley, Reading (2000)
Unruh, E.: Prime number computation. ANSI X3J16-94-0075/ISO WG21-462
Veldhuizen, T.L., Gannon, D.: Active libraries: Rethinking the roles of compilers and libraries. In: Proceedings of the SIAM Workshop on Object Oriented Methods for Interoperable Scientic and Engineering Computing (OO 1998), pp. 21–23. SIAM Press, Philadelphia (1998)
Veldhuizen, T.L.: Expression Templates. C++ Report 7(5), 26–31 (1995)
Veldhuizen, T.L.: Using C++ Template Metaprograms. C++ Report 7(4), 36–43 (1995)
Veldhuizen, T.L.: C++ Templates as Partial Evaluation. In: Danvy, O. (ed.): Proceedings of the 1999 ACM SIGPLAN Workshop on Partial Evaluation and Semantics-Based Program Manipulation, San Antonio, Texas, January 22-23. Technical report BRICS-NS-99-1, University of Aarhus, pp. 13–18 (1999)
Boost Concept checking, http://www.boost.org/libs/concept_check/concept_check.htm
Boost Metaprogramming library, http://www.boost.org/libs/mpl/doc/index.html
The boost preprocessor metaprogramming library, http://www.boost.org/doc/libs/1_41_0/libs/preprocessor/doc/index.html
The boost proto library, http://www.boost.org/doc/libs/1_37_0/doc/html/proto.html
http://www.boost.org/doc/libs/1_42_0/libs/mpl/doc/refmanual/string.html
http://www.boost.org/doc/libs/1_40_0/libs/mpl/doc/refmanual/vector-c.html
The boost xpressive regular library, http://www.boost.org/doc/libs/1_40_0/doc/html/xpressive.htm
Author information
Authors and Affiliations
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2011 Springer-Verlag Berlin Heidelberg
About this chapter
Cite this chapter
Szűgyi, Z., Sinkovics, Á., Pataki, N., Porkoláb, Z. (2011). C++ Metastring Library and Its Applications. In: Fernandes, J.M., Lämmel, R., Visser, J., Saraiva, J. (eds) Generative and Transformational Techniques in Software Engineering III. GTTSE 2009. Lecture Notes in Computer Science, vol 6491. Springer, Berlin, Heidelberg. https://doi.org/10.1007/978-3-642-18023-1_15
Download citation
DOI: https://doi.org/10.1007/978-3-642-18023-1_15
Publisher Name: Springer, Berlin, Heidelberg
Print ISBN: 978-3-642-18022-4
Online ISBN: 978-3-642-18023-1
eBook Packages: Computer ScienceComputer Science (R0)