ABSTRACT
Generic 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, the power of templates comes with a price: generic (template) libraries can be more difficult to use and develop than non-template libraries and their misuse results in notoriously confusing error messages. As currently defined in C++98, templates are unconstrained, and type-checking of templates is performed late in the compilation process, i.e., after the use of a template has been combined with its definition. To improve the support for generic programming in C++, we introduce concepts to express the syntactic and semantic behavior of types and to constrain the type parameters in a C++ template. Using concepts, type-checking of template definitions is separated from their uses, thereby making templates easier to use and easier to compile. These improvements are achieved without limiting the flexibility of templates or decreasing their performance - in fact their expressive power is increased. This paper describes the language extensions supporting concepts, their use in the expression of the C++ Standard Template Library, and their implementation in the ConceptGCC compiler. Concepts are candidates for inclusion in the upcoming revision of the ISO C++ standard, C++0x.
- David Abrahams and Aleksey Gurtovoy. C++ Template Metaprogramming: Concepts, Tools, and Techniques from Boost and Beyond. Addison-Wesley, 2004.]] Google Scholar
Digital Library
- P. An, A. Jula, S. Rus, S. Saunders, T. Smith, G. Tanase, N. Thomas, N. Amato, and L. Rauchwerger. STAPL: A standard template adaptive parallel C++ library. In Int. Wkshp on Adv. Compiler Technology for High Perf. and Embedded Processors, page 10, July 2001.]]Google Scholar
- Matthew H. Austern. Generic programming and the STL: Using and extending the C++ Standard Template Library. Professional Computing Series. Addison-Wesley Longman Publishing Co., Inc., Boston, MA, USA, 1998.]] Google Scholar
Digital Library
- G. Baumgartner, M. Jansche, and K. Läufer. Half & Half: Multiple Dispatch and Retroactive Abstraction for Java. Technical Report OSU-CISRC-5/01-TR08, Ohio State University, 2002.]]Google Scholar
- Gerald Baumgartner and Vincent F. Russo. Signatures: A language extension for improving type abstraction and subtype polymorphism in C++. Software--Practice and Experience, 25(8):863--889, August 1995.]] Google Scholar
Digital Library
- Boost. Boost C++ L ibraries. http://www.boost.org/.]]Google Scholar
- Alex Breuer, Peter Gottschling, Douglas Gregor, and Andrew Lumsdaine. Effecting parallel graph eigensolvers through library composition. In Performance Optimization for High-Level Languages and Libraries (POHLL), April 2006.]]Google Scholar
Digital Library
- Peter Canning, William Cook, Walter Hill, Walter Olthoff, and John C. Mitchell. F-bounded polymorphism for object-oriented programming. In FPCA '89: Proceedings of the fourth international conference on Functional programming languages and computer architecture, pages 273--280. ACM Press, 1989.]] Google Scholar
Digital Library
- Manuel M. T. Chakravarty, Gabrielle Keller, and Simon Peyton Jones. Associated type synonyms. In ICFP '05: Proceedings of the International Conference on Functional Programming, pages 241--253. ACM Press, September 2005.]] Google Scholar
Digital Library
- Manuel M. T. Chakravarty, Gabrielle Keller, Simon Peyton Jones, and Simon Marlow. Associated types with class. In POPL '05: Proceedings of the 32nd ACM SIGPLAN-SIGACT symposium on Principles of programming languages, pages 1--13. ACM Press, 2005.]] Google Scholar
Digital Library
- K. Czarnecki and U. Eisenecker. Generative Programming: Methods, Techniques and Applications. Addison-Wesley, 2000.]] Google Scholar
Digital Library
- Gabriel Dos Reis and Bjarne Stroustrup. Specifying C++ concepts. In POPL '06: Conference record of the 33rd ACM SIGPLAN-SIGACT symposium on Principles of programming languages, pages 295--308. ACM Press, 2006.]] Google Scholar
Digital Library
- Peter J. Downey, Ravi Sethi, and Robert Endre Tarjan. Variations on the common subexpression problem. Journal of the ACM (JACM), 27(4):758--771, 1980.]] Google Scholar
Digital Library
- A. Fabri, G.-J. Giezeman, L. Kettner, S. Schirra, and S. Schönherr. On the design of CGAL, a computational geometry algorithms library. Software - Practice and Experience, 30(11):1167--1202, 2000. Special Issue on Discrete Algorithm Engineering.]] Google Scholar
Digital Library
- Ronald Garcia, Jaakko Järvi, Andrew Lumsdaine, Jeremy Siek, and Jeremiah Willcock. A comparative study of language support for generic programming. In OOPSLA '03: Proceedings of the 18th annual ACM SIGPLAN conference on Object-oriented programing, systems, languages, and applications, pages 115--134. ACM Press, 2003.]] Google Scholar
Digital Library
- Ronald Garcia, Jaakko Järvi, Andrew Lumsdaine, Jeremy Siek, and Jeremiah Willcock. An extended comparative study of language support for generic programming. Journal of Functional Programming, 2005. Accepted.]] Google Scholar
Digital Library
- GNU compiler collection. http://www.gnu.org/software/gcc/, 2005.]]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 Scholar
Digital Library
- Douglas Gregor. ConceptGCC: Concept extensions for C++. http://www.generic-programming.org/software/ConceptGCC, 2005.]]Google Scholar
- Douglas Gregor and Andrew Lumsdaine. Lifting sequential graph algorithms for distributed-memory parallel computation. In Proceedings of the 2005 ACM SIGPLAN conference on Object-oriented programming, systems, languages, and applications (OOPSLA '05), pages 423--437, October 2005.]] Google Scholar
Digital Library
- Douglas Gregor and Jeremy Siek. Implementing concepts. Technical Report N1848=05-0108, ISO/IEC JTC 1, Information Technology, Subcommittee 22, Programming Language C++, August 2005.]]Google Scholar
- Douglas Gregor, Jeremy Siek, Jeremiah Willcock, Jaakko Järvi, Ronald Garcia, and Andrew Lumsdaine. Concepts for C++0x (revision 1). Technical Report N1849=05-0109, ISO/IEC JTC 1, Information Technology, Subcommittee 22, Programming Language C++, August 2005.]]Google Scholar
- Douglas Gregor and Bjarne Stroustrup. Concepts. Technical Report N2042=06-0112, ISO/IEC JTC 1, Information Technology, Subcommittee 22, Programming Language C++, June 2006.]]Google Scholar
- Michi Henning. The rise and fall of CORBA. ACM Queue, 4(5):28--34, June 2006.]] Google Scholar
Digital Library
- International Organization for Standardization. ISO/IEC 14882:1998: Programming languages - C++. Geneva, Switzerland, September 1998.]]Google Scholar
- J. Järvi, B. Stroustrup, and G. Dos Reis. Decltype and auto (revision 4). Technical Report N1705=04-0145, ISO/IEC JTC 1, Information Technology, Subcommittee 22, Programming Language C++, September 2004. http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1705.pdf.]]Google Scholar
- Jaakko Järvi, Douglas Gregor, Jeremiah Willcock, Andrew Lumsdaine, and Jeremy Siek. Algorithm specialization in generic programming: Challenges of constrained generics in C++. In PLDI '06: Proceedings of the 2006 ACM SIGPLAN conference on Programming language design and implementation, pages 272--282. ACM Press, 2006.]] Google Scholar
Digital Library
- Jaakko Järvi, Jeremiah Willcock, Howard Hinnant, and Andrew Lumsdaine. Function overloading based on arbitrary properties of types. C/C++ Users Journal, 21(6):25--32, June 2003.]]Google Scholar
- Jaakko Järvi, Jeremiah Willcock, and Andrew Lumsdaine. Associated types and constraint propagation for mainstream object-oriented generics. In OOPSLA '05: Proceedings of the 20th annual ACM SIGPLAN conference on Object-oriented programming systems languages and applications, pages 1--19. ACM Press, 2005.]] Google Scholar
Digital Library
- Mehdi Jazayeri, Rüdiger Loos, David Musser, and Alexander Stepanov. Generic Programming. In Report of the Dagstuhl Seminar on Generic Programming, Schloss Dagstuhl, Germany, April 1998.]] Google Scholar
Digital Library
- D. Kapur and D. Musser. Tecton: a framework for specifying and verifying generic system components. Technical Report RPI--92--20, Department of Computer Science, Rensselaer Polytechnic Institute, Troy, New York 12180, July 1992.]]Google Scholar
- Steve Karmesin, James Crotinger, Julian Cummings, Scott Haney, William Humphrey, John Reynders, Stephen Smith, and Timothy J. Williams. Array design and expression evaluation in POOMA II. In Denis Caromel, Rodney R. Oldehoeft, and Marydell Tholburn, editors, ISCOPE. Advanced Computing Laboratory, LANL, 1998.]] Google Scholar
Digital Library
- K. Läufer, G. Baumgartner, and V. F. Russo. Safe structural conformance for Java. The Computer Journal, 43(6):469--481, 2000.]]Google Scholar
Cross Ref
- Lie-Quan Lee, Jeremy Siek, and Andrew Lumsdaine. Generic graph algorithms for sparse matrix ordering. In ISCOPE'99, Lecture Notes in Computer Science. Springer-Verlag, 1999.]] Google Scholar
Digital Library
- Xavier Leroy. Manifest types, modules, and separate compilation. In Proceedings of the 21st Annual ACM Symposium on Principles of Programming Languages, pages 109--122, 1994.]] Google Scholar
Digital Library
- Mark Lillibridge. Translucent Sums: A Foundation for Higher-Order Module Systems. PhD thesis, Pittsburgh, PA, May 1997.]]Google Scholar
- Vassily Litvinov. Contraint-based polymorphism in Cecil: towards a practical and static type system. In OOPSLA '98: Proceedings of the 13th ACM SIGPLAN conference on Object-oriented programming, systems, languages, and applications, pages 388--411. ACM Press, 1998.]] Google Scholar
Digital Library
- O. L. Madsen and B. Moller-Pedersen. Virtual classes: a powerful mechanism in object-oriented programming. In OOPSLA '89: Conference proceedings on Object-oriented programming systems, languages and applications, pages 397--406. ACM Press, 1989.]] Google Scholar
Digital Library
- Bertrand Meyer. Eiffel: the Language. Prentice Hall, first edition, 1992.]] Google Scholar
Digital Library
- Microsoft Corporation. Generics in C#, September 2002. Part of the Gyro distribution of generics for .NET available at http://research.microsoft.com/projects/clrgen/.]]Google Scholar
- Robin Milner, Mads Tofte, and Robert Harper. The Definition of Standard ML. MIT Press, 1990.]] Google Scholar
Digital Library
- David R. Musser, Gillmer J. Derge, and Atul Saini. STL Tutorial and Reference Guide. Addison-Wesley, 2nd edition, 2001.]] Google Scholar
Digital Library
- David R. Musser and Alexander A. Stepanov. A library of generic algorithms in Ada. In Using Ada (1987 International Ada Conference), pages 216--225. ACM SIGAda, December 1987.]] Google Scholar
Digital Library
- David R. Musser and Alexander A. Stepanov. Generic programming. In P. (Patrizia) Gianni, editor, Symbolic and algebraic computation: ISSAC '88, Rome, Italy, July 4--8, 1988: Proceedings, volume 358 of Lecture Notes in Computer Science, pages 13--25, Berlin, 1989. Springer Verlag.]] Google Scholar
Digital Library
- David R. Musser and Alexander A. Stepanov. Algorithm-oriented generic libraries. Software - Practice and Experience, 24(7):623--642, July 1994.]] Google Scholar
Digital Library
- Nathan Myers. A new and useful technique: "traits". C ++ Report, 7(5):32--35, June 1995.]]Google Scholar
- Nathan C. Myers. Traits: a new and useful template technique. C ++ Report, June 1995.]]Google Scholar
- Greg Nelson and Derek C. Oppen. Fast decision procedures based on congruence closure. J. ACM, 27(2):356--364, 1980.]] Google Scholar
Digital Library
- Martin Odersky. The Scala language specification: Version 2.0, draft March 17, 2006. http://scala.epfl.ch/docu/files/ScalaReference.pdf, 2006.]]Google Scholar
- Martin Odersky and al. An overview of the Scala programming language. Technical Report IC/2004/64, EPFL Lausanne, Switzerland, 2004.]]Google Scholar
- Martin Odersky and Matthias Zenger. Scalable component abstractions. SIGPLAN Not., 40(10):41--57, 2005.]] Google Scholar
Digital Library
- Sibylle Schupp, Douglas Gregor, David R. Musser, and Shin-Ming Liu. User-extensible simplification: Type-based optimizer generators. In CC '01: Proceedings of the 10th International Conference on Compiler Construction, pages 86--101, London, UK, 2001. Springer-Verlag.]] Google Scholar
Digital Library
- Jeremy Siek, Douglas Gregor, Ronald Garcia, Jeremiah Willcock, Jaakko Järvi, and Andrew Lumsdaine. Concepts for C++0x. Technical Report N1758=05-0018, ISO/IEC JTC 1, Information Technology, Subcommittee 22, Programming Language C++, January 2005.]]Google Scholar
- Jeremy Siek, Lie-Quan Lee, and Andrew Lumsdaine. The Boost Graph Library: User Guide and Reference Manual. Addison-Wesley Longman Publishing Co., Inc., Boston, MA, USA, 2002.]] Google Scholar
Digital Library
- Jeremy Siek and Andrew Lumsdaine. The Matrix Template Library: Generic components for high-performance scientific computing. Computing in Science and Engineering, 1(6):70--78, Nov/Dec 1999.]] Google Scholar
Digital Library
- Jeremy Siek and Andrew Lumsdaine. Concept checking: Binding parametric polymorphism in C++. In First Workshop on C++ Template Programming, October 2000.]]Google Scholar
- Jeremy Siek and Andrew Lumsdaine. Essential language support for generic programming. In PLDI '05: Proceedings of the ACM SIGPLAN 2005 conference on Programming language design and implementation, pages 73--84. ACM Press, June 2005.]] Google Scholar
Digital Library
- Jeremy Siek and Andrew Lumsdaine. Language requirements for large-scale generic libraries. In GPCE '05: Proceedings of the fourth international conference on Generative Programming and Component Engineering, September 2005. To appear.]] Google Scholar
Digital Library
- Jeremy G. Siek. A Language for Generic Programming. PhD thesis, Indiana University, August 2005.]] Google Scholar
Digital Library
- Alexander A. Stepanov and Meng Lee. The Standard Template Library. Technical Report X3J16/94-0095, WG21/N0482, ISO Programming Language C++ Project, May 1994.]]Google Scholar
- Bjarne Stroustrup. Design and Evolution of C++. Addison-Wesley Longman Publishing Co., Inc., Boston, MA, USA, 1994.]] Google Scholar
Digital Library
- Bjarne Stroustrup. The C++ Programming Language. Addison-Wesley, special edition, 2000.]] Google Scholar
Digital Library
- Bjarne Stroustrup and Gabriel Dos Reis. Concepts - design choices for template argument checking. Technical Report N1522=03-0105, ISO/IEC JTC 1, Information Technology, Subcommittee 22, Programming Language C++, October 2003. http://www.open-std.org/jtc1/sc22/wg21.]]Google Scholar
- Bjarne Stroustrup and Gabriel Dos Reis. A concept design (rev. 1). Technical Report N1782=05-0042, ISO/IEC JTC 1, Information Technology, Subcommittee 22, Programming Language C++, May 2005.]]Google Scholar
- Mathias Troyer and Prakash Dayal. The Iterative Eigensolver Template Library. http://www.comp-phys.org:16080/software/ietl/.]]Google Scholar
- Todd Veldhuizen. Using C ++ template metaprograms. C++ Report, May 1995.]]Google Scholar
- Todd L. Veldhuizen. Expression templates. C++ Report, 7(5):26--31, June 1995. Reprinted in C++ Gems, ed. Stanley Lippman.]] Google Scholar
Digital Library
- Todd L. Veldhuizen. Arrays in Blitz++. In Proceedings of the 2nd International Scientific Computing in Object-Oriented Parallel Environments (ISCOPE'98), volume 1505 of Lecture Notes in Computer Science. Springer-Verlag, 1998.]] Google Scholar
Digital Library
- Todd L. Veldhuizen. Five compilation models for C++ templates. In First Workshop on C++ Template Programming, October 10 2000.]]Google Scholar
- P. Wadler and S. Blott. How to make ad-hoc polymorphism less ad-hoc. In ACM Symposium on Principles of Programming Languages, pages 60--76. ACM, January 1989.]] Google Scholar
Digital Library
Index Terms
Concepts: linguistic support for generic programming in C++
Recommendations
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++
Proceedings of the 2006 OOPSLA ConferenceGeneric 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, ...
Algorithm specialization in generic programming: challenges of constrained generics in C++
PLDI '06: Proceedings of the 27th ACM SIGPLAN Conference on Programming Language Design and ImplementationGeneric programming has recently emerged as a paradigm for developing highly reusable software libraries, most notably in C++. We have designed and implemented a constrained generics extension for C++ to support modular type checking of generic ...







Comments