Meta C++: an extension layer for multi-stage generative metaprogramming

Generative metaprogramming is a powerful mechanism for reuse through code manipulation, adaptation and composition. Its practicing is complex, involving development demands similar to any actual system. In C++, metaprogramming is currently practiced with templates, requiring a functional programming style that is in contrast to the imperative object-oriented nature of the main language. Thus, metaprograms bear little resemblance to normal programs, and involve different programming approaches in their development, effectively disabling any possibility for design or code reuse between them. In this paper, we propose MetaC++, an extension layer supporting multi-stage generative metaprogramming for C++, offering the full-range of language constructs for implementing compile-time metaprograms and allowing them to share development practices with normal programs. We present its design and implementation, and outline the importance of such an extension to C++ through a number of advanced application scenarios.

[1]  Aaron Turon,et al.  Metaprogramming with Traits , 2007, ECOOP.

[2]  Yannis Smaragdakis,et al.  JTS: tools for implementing domain-specific languages , 1998, Proceedings. Fifth International Conference on Software Reuse (Cat. No.98TB100203).

[3]  Anthony Savidis,et al.  An integrated implementation framework for compile‐time metaprogramming , 2015, Softw. Pract. Exp..

[4]  Shigeru Chiba,et al.  A metaobject protocol for C++ , 1995, OOPSLA.

[5]  Simon L. Peyton Jones,et al.  Template meta-programming for Haskell , 2002, Haskell '02.

[6]  Robert Glück,et al.  Efficient Multi-level Generating Extensions for Program Specialization , 1995, PLILP.

[7]  Walid Taha,et al.  A Gentle Introduction to Multi-stage Programming , 2003, Domain-Specific Program Generation.

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

[9]  Dawson R. Engler,et al.  C and tcc: a language and compiler for dynamic code generation , 1999, TOPL.

[10]  Jr. Guy L. Steele,et al.  Common LISP: the language (2nd ed.) , 1990 .

[11]  Shan Shan Huang,et al.  Statically safe program generation with safegen , 2005, GPCE'05.

[12]  Brian W. Kernighan,et al.  The C Programming Language , 1978 .

[13]  Tim Sheard Using MetaML: A Staged Programming Language , 1998, Advanced Functional Programming.

[14]  Walid Taha,et al.  MetaML and multi-stage programming with explicit annotations , 2000, Theor. Comput. Sci..

[15]  Shan Shan Huang,et al.  Morphing: Structurally shaping a class by reflecting on others , 2011, TOPL.

[16]  Anthony Savidis,et al.  An Integrated Approach to Source Level Debugging and Compile Error Reporting in Metaprograms , 2013, J. Object Technol..

[17]  James R. Larus,et al.  Reflective program generation with patterns , 2006, GPCE '06.

[18]  Laurence Tratt,et al.  Domain Specific Language Implementation via Compile-Time MetaProgramming , 2008 .

[19]  Elena Zucca,et al.  MetaFJig: a meta-circular composition language for Java-like classes , 2010, OOPSLA.

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

[21]  Todd L. Veldhuizen,et al.  C++ Templates are Turing Complete , 2003 .

[22]  Daniel Weise,et al.  Programmable syntax macros , 1993, PLDI '93.

[23]  Paul Roe,et al.  Metaphor: A Multi-stage, Object-Oriented Programming Language , 2004, GPCE.

[24]  Tim Sheard,et al.  Accomplishments and Research Challenges in Meta-programming , 2001, SAIG.

[25]  Scott F. Smith,et al.  Backstage Java: making a difference in metaprogramming , 2011, OOPSLA '11.

[26]  Alan Bawden,et al.  Quasiquotation in Lisp , 1999, PEPM.

[27]  Walid Taha,et al.  A Bytecode-Compiled, Type-safe, Multi-Stage Language , 2001 .

[28]  Walid Taha,et al.  Mint: Java multi-stage programming using weak separability , 2010, PLDI '10.

[29]  Ralph Johnson,et al.  design patterns elements of reusable object oriented software , 2019 .

[30]  Anthony Savidis,et al.  Implementing Reusable Exception Handling Patterns with Compile-Time Metaprogramming , 2012, SERENE.

[31]  Matthias Felleisen,et al.  Hygienic macro expansion , 1986, LFP '86.

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