ABSTRACT
Generic functions and classes accepting a variable number of type arguments have proven to be a very useful, but missing, feature of C++. Numerous foundational libraries rely on clever template and preprocessor tricks to emulate such variadic templates. By several measures these emulations are inadequate. This paper describes how C++ can be extended with variadic templates, significantly improving existing implementations of widely used C++ libraries in terms of code size, quality of error diagnostics, compilation speed, and generality. Furthermore, variadic templates enable new applications, such as type-safe implementations of functions like printf, and improved support for generic mixin classes. We have implemented variadic templates as an extension of a production quality C++ compiler.
- Peter Dimov. The Boost Bind library. http://www.boost.org/libs/bind/bind.html, August 2001.Google Scholar
- Jaakko Järvi, Gary Powell, and Andrew Lumsdaine. The Lambda Library: unnamed functions in C++ Software---Practice and Experience, 33:259--291, 2003. Google ScholarDigital Library
- Jaakko Järvi. Tuple types and multiple return values. C/C++ Users Journal, 19:24--35, August 2001. Google ScholarDigital Library
- Dan Marsden Joel de Guzman. Boost Fusion. http://spirit.sourceforge.net/dl_more/fusion_v2/libs/fusion/doc/html/index.html, 2006.Google Scholar
- Douglas Gregor. Boost.Function. Boost. http://www.boost.org/doc/html/function.html.Google Scholar
- Aleksei Gurtovoy and David Abrahams. The Boost C++ metaprogramming library. www.boost.org/libs/mp1, 2002.Google Scholar
- Pete Becker. Working draft, standard for programming language C++. Technical Report N2009=06-0079, ISO/IEC JTC 1, Information Technology, Subcommittee SC 22, Programming Language C++, April 2006.Google Scholar
- Douglas Gregor. Variadic templates for GCC. http://www.osl.iu.edu/~dgregor/cpp/variadic-templates.html, August 2006.Google Scholar
- Vesa Karvonen and Paul Mensonides. The Boost Preprocessor library, http://www.boost.org/libs/preprocessor/doc/index.html, July 2001.Google Scholar
- Douglas Gregor. {libstdc++ patch} trl::bind, take 2. GNU libstdc++ mailing list, March 2005. http://gcc.gnu.org/ml/libstdc++/2005--03/msg00367.html.Google Scholar
- Yannis Smaragdakis and Don S. Batory. Mixin-based programming in C++. In GCSE '00: Proceedings of the Second International Symposium on Generative and Component-Based Software Engineering, pages 163--177, London, UK, 2001. Springer-Verlag. Google ScholarDigital Library
- Howard E. Hinnant, Dave Abrahams, and Peter Dimov. A proposal to add an rvalue reference to the C++ language. Technical Report N1690=04-0130, ISO/IEC JTC 1, Information technology, Subcommittee SC 22, Programming language C++, September 2004. http://www.open-std.org/jtcl/sc22/wg21/docs/papers/2004/n1690.html.Google Scholar
- Joel de Guzman. The Spirit C++ parser framework. http://spirit.sourceforge.net, 2006.Google Scholar
- Andrei Alexandrescu. Modern C++ Design: Generic Programming and Design Patterns Applied. Addison-Wesley, 2001. Google ScholarDigital Library
- Todd L. Veldhuizen. C++ templates are Turing complete, www.osl.iu.edu/~tveldhui/papers/2003/turing.pdf, 2003.Google Scholar
- Matt Austern. (Draft) Technical Report on Standard Library Extensions. Number N1660=04-0100 in ISO C++ Standard Committee 2004--07 mailing, 2004.Google Scholar
- James Gosling, Bill Joy, Guy Steele, and Gilad Bracha. The Java Language Specification, Third Edition. Addison-Wesley Longman Publishing Co., Inc., Boston, MA, USA, 2005. Google ScholarDigital Library
- ECMA. C# Language Specification, June 2005. http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-334.pdf.Google Scholar
- David A. Hall. Variable number of generic params. Java bug report 6261297: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6261279, 2005.Google Scholar
- Walter Bright. D programming language. http://www.digitalmars.com/d/, 2006.Google Scholar
- Olivier Danvy. Functional unparsing. Journal of Functional Programming, 8(6):621--625, 1998. Google ScholarDigital Library
- Tim Sheard and Simon Peyton Jones. Template meta-programming for haskell. SIGPLAN Not., 37(12):60--75, 2002. Google ScholarDigital Library
- Bruno C. d. S. Oliveira and Jeremy Gibbons. Typecase: a design pattern for type-indexed functions. In Haskell '05: Proceedings of the 2005 ACM SIGPLAN workshop on Haskell, pages 98--109, New York, NY, USA, 2005. ACM Press. Google ScholarDigital Library
- Samuel Krempp. The Boost Formatambda library. http://www.boost.org/libs/format, 2002.Google Scholar
- H. Abelson, R. K. Dybvig, C. T. Haynes, G. J. Rozas, N. I. Adams Iv, D. P. Friedman, E. Kohlbecker, Jr. G. L. Steele, D. H. Bartley, R. Halstead, D. Oxley, G. J. Sussman, G. Brooks, C. Hanson, K. M. Pitman, and M. Wand. Revised5 report on the algorithmic language Scheme. Higher-Order and Symbolic Computation, 11(1):7--105, 1998. Google ScholarDigital Library
- Douglas Gregor, Gary Powell, and Jaakko Järvi. Typesafe variable-length function and template argument lists. Number N1483=03-0066 in ISO C++ Standard Committee Post-Oxford mailing, April 2003.Google Scholar
- Douglas Gregor, Jaakko Järvi, and Gary Powell. Variadic templates. Number N1603=04-0043 in ISO C++ Standard Committee Pre-Sydney mailing, February 2004.Google Scholar
- Douglas Gregor, Jaakko Järvi, and Gary Powell. Variadic templates: Exploring the design space. Number N1704=04-0144 in ISO C++ Standard Committee Pre-Redmond mailing, September 2004.Google Scholar
Index Terms
- Variadic templates for C++
Recommendations
C++ templates considered harmful
C++ is considered by many professional software developers and educators to be the lingua franca of programming languages. Once mastered, its power of expression is nearly limitless for the class of problems for which an imperative and object-oriented ...
Specifying C++ concepts
Proceedings of the 2006 POPL ConferenceC++ templates are key to the design of current successful mainstream libraries and systems. They are the basis of programming techniques in diverse areas ranging from conventional general-purpose programming to software for safety-critical embedded ...
Concepts: linguistic support for generic programming in C++
OOPSLA '06: Proceedings of the 21st annual ACM SIGPLAN conference on Object-oriented programming systems, languages, and applicationsGeneric programming has emerged as an important technique for the development of highly reusable and efficient software libraries. In C++, generic programming is enabled by the flexibility of templates, the C++ type parametrization mechanism. However, ...
Comments