Skip to main content

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.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

eBook
USD 16.99
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 54.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. Alexandrescu, A.: Modern C++ Design: Generic Programming and Design Patterns Applied. Addison-Wesley, Reading (2001)

    Google Scholar 

  2. Abrahams, D., Gurtovoy, A.: C++ Template Metaprogramming: Concepts, Tools, and Techniques from Boost and Beyond. Addison-Wesley, Reading (2004)

    Google Scholar 

  3. Boyer, R.S., Moore, J.S.: A Fast String Searching Algorithm. Communication of the ACM 20, 762–772 (1977)

    Article  MATH  Google Scholar 

  4. Cormen, T.H., Leiserson, C.E., Rivest, R.L., Stein, C.: Introduction to Algorithms. The MIT Press, Cambridge (2001)

    MATH  Google Scholar 

  5. Czarnecki, K., Eisenecker, U.W.: Generative Programming: Methods, Tools and Applications. Addison-Wesley, Reading (2000)

    Google Scholar 

  6. Czarnecki, K., Eisenecker, U.W., Glück, R., Vandevoorde, D., Veldhuizen, T.L.: Generative Programming and Active Libraries. Springer, Heidelberg (2000)

    Book  Google Scholar 

  7. 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)

    Google Scholar 

  8. 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)

    Google Scholar 

  9. 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)

    Google Scholar 

  10. Gregor, D., Järvi, J., Powell, G.: Variadic Templates (Revision 3). Number N2080=06-0150, ANSI/ISO C++ Standard Committee (October 2006)

    Google Scholar 

  11. 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)

    Article  Google Scholar 

  12. Jones, N.D.: An introduction to partial evaluation. ACM Computing Surveys 28(3), 480–503 (1996)

    Article  Google Scholar 

  13. 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

    Google Scholar 

  14. Karlsson, B.: Beyond the C++ Standard Library, An Introduction to Boost. Addison-Wesley, Reading (2005)

    Google Scholar 

  15. Knuth, D.E., Morris Jr., J.H., Pratt, V.R.: Fast Pattern Matching in Strings. SIAM J. Comput. 6(2), 323–350 (1977)

    Article  MathSciNet  MATH  Google Scholar 

  16. Meyers, S.: Effective STL. Addison-Wesley, Reading (2001)

    Google Scholar 

  17. 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)

    Google Scholar 

  18. ANSI/ISO C++ Committee. Programming Languages – C++. ISO/IEC 14882:1998(E). American National Standards Institute (1998)

    Google Scholar 

  19. Siek, J., Lumsdaine, A.: Concept checking: Binding parametric polymorphism in C++. In: First Workshop on C++ Template Metaprogramming (October 2000)

    Google Scholar 

  20. 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)

    Google Scholar 

  21. Stroustrup, B.: Evolving a language in and for the real world: C++ 1991-2006. ACM HOPL-III (June 2007)

    Google Scholar 

  22. Stroustrup, B.: The C++ Programming Language Special Edition. Addison- Wesley, Reading (2000)

    MATH  Google Scholar 

  23. Unruh, E.: Prime number computation. ANSI X3J16-94-0075/ISO WG21-462

    Google Scholar 

  24. 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)

    Google Scholar 

  25. Veldhuizen, T.L.: Expression Templates. C++ Report 7(5), 26–31 (1995)

    Google Scholar 

  26. Veldhuizen, T.L.: Using C++ Template Metaprograms. C++ Report 7(4), 36–43 (1995)

    Google Scholar 

  27. 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)

    Google Scholar 

  28. http://www.research.att.com/~bs/C++0xFAQ.html

  29. Boost Concept checking, http://www.boost.org/libs/concept_check/concept_check.htm

  30. Boost Metaprogramming library, http://www.boost.org/libs/mpl/doc/index.html

  31. The boost preprocessor metaprogramming library, http://www.boost.org/doc/libs/1_41_0/libs/preprocessor/doc/index.html

  32. The boost proto library, http://www.boost.org/doc/libs/1_37_0/doc/html/proto.html

  33. http://spirit.sourceforge.net

  34. http://www.boost.org/doc/libs/1_42_0/libs/mpl/doc/refmanual/string.html

  35. http://valgrind.org

  36. http://www.boost.org/doc/libs/1_40_0/libs/mpl/doc/refmanual/vector-c.html

  37. http://www.boost.org/doc/libs/1_40_0/libs/wave/index.html

  38. The boost xpressive regular library, http://www.boost.org/doc/libs/1_40_0/doc/html/xpressive.htm

Download references

Author information

Authors and Affiliations

Authors

Editor information

Editors and Affiliations

Rights and permissions

Reprints 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)

Publish with us

Policies and ethics