skip to main content
10.1145/1167473.1167499acmconferencesArticle/Chapter ViewAbstractPublication PagessplashConference Proceedingsconference-collections
Article

Concepts: linguistic support for generic programming in C++

Published:16 October 2006Publication History

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.

References

  1. David Abrahams and Aleksey Gurtovoy. C++ Template Metaprogramming: Concepts, Tools, and Techniques from Boost and Beyond. Addison-Wesley, 2004.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. 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 ScholarGoogle Scholar
  3. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  4. 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 ScholarGoogle Scholar
  5. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  6. Boost. Boost C++ L ibraries. http://www.boost.org/.]]Google ScholarGoogle Scholar
  7. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  8. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  9. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  10. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  11. K. Czarnecki and U. Eisenecker. Generative Programming: Methods, Techniques and Applications. Addison-Wesley, 2000.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  13. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  14. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  15. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  16. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  17. GNU compiler collection. http://www.gnu.org/software/gcc/, 2005.]]Google ScholarGoogle Scholar
  18. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  19. Douglas Gregor. ConceptGCC: Concept extensions for C++. http://www.generic-programming.org/software/ConceptGCC, 2005.]]Google ScholarGoogle Scholar
  20. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  21. 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 ScholarGoogle Scholar
  22. 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 ScholarGoogle Scholar
  23. 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 ScholarGoogle Scholar
  24. Michi Henning. The rise and fall of CORBA. ACM Queue, 4(5):28--34, June 2006.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. International Organization for Standardization. ISO/IEC 14882:1998: Programming languages - C++. Geneva, Switzerland, September 1998.]]Google ScholarGoogle Scholar
  26. 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 ScholarGoogle Scholar
  27. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  28. 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 ScholarGoogle Scholar
  29. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  30. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  31. 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 ScholarGoogle Scholar
  32. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  33. K. Läufer, G. Baumgartner, and V. F. Russo. Safe structural conformance for Java. The Computer Journal, 43(6):469--481, 2000.]]Google ScholarGoogle ScholarCross RefCross Ref
  34. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  35. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  36. Mark Lillibridge. Translucent Sums: A Foundation for Higher-Order Module Systems. PhD thesis, Pittsburgh, PA, May 1997.]]Google ScholarGoogle Scholar
  37. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  38. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  39. Bertrand Meyer. Eiffel: the Language. Prentice Hall, first edition, 1992.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  40. 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 ScholarGoogle Scholar
  41. Robin Milner, Mads Tofte, and Robert Harper. The Definition of Standard ML. MIT Press, 1990.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  42. David R. Musser, Gillmer J. Derge, and Atul Saini. STL Tutorial and Reference Guide. Addison-Wesley, 2nd edition, 2001.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  43. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  44. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  45. David R. Musser and Alexander A. Stepanov. Algorithm-oriented generic libraries. Software - Practice and Experience, 24(7):623--642, July 1994.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  46. Nathan Myers. A new and useful technique: "traits". C ++ Report, 7(5):32--35, June 1995.]]Google ScholarGoogle Scholar
  47. Nathan C. Myers. Traits: a new and useful template technique. C ++ Report, June 1995.]]Google ScholarGoogle Scholar
  48. Greg Nelson and Derek C. Oppen. Fast decision procedures based on congruence closure. J. ACM, 27(2):356--364, 1980.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  49. Martin Odersky. The Scala language specification: Version 2.0, draft March 17, 2006. http://scala.epfl.ch/docu/files/ScalaReference.pdf, 2006.]]Google ScholarGoogle Scholar
  50. Martin Odersky and al. An overview of the Scala programming language. Technical Report IC/2004/64, EPFL Lausanne, Switzerland, 2004.]]Google ScholarGoogle Scholar
  51. Martin Odersky and Matthias Zenger. Scalable component abstractions. SIGPLAN Not., 40(10):41--57, 2005.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  52. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  53. 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 ScholarGoogle Scholar
  54. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  55. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  56. Jeremy Siek and Andrew Lumsdaine. Concept checking: Binding parametric polymorphism in C++. In First Workshop on C++ Template Programming, October 2000.]]Google ScholarGoogle Scholar
  57. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  58. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  59. Jeremy G. Siek. A Language for Generic Programming. PhD thesis, Indiana University, August 2005.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  60. 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 ScholarGoogle Scholar
  61. Bjarne Stroustrup. Design and Evolution of C++. Addison-Wesley Longman Publishing Co., Inc., Boston, MA, USA, 1994.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  62. Bjarne Stroustrup. The C++ Programming Language. Addison-Wesley, special edition, 2000.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  63. 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 ScholarGoogle Scholar
  64. 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 ScholarGoogle Scholar
  65. Mathias Troyer and Prakash Dayal. The Iterative Eigensolver Template Library. http://www.comp-phys.org:16080/software/ietl/.]]Google ScholarGoogle Scholar
  66. Todd Veldhuizen. Using C ++ template metaprograms. C++ Report, May 1995.]]Google ScholarGoogle Scholar
  67. Todd L. Veldhuizen. Expression templates. C++ Report, 7(5):26--31, June 1995. Reprinted in C++ Gems, ed. Stanley Lippman.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  68. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  69. Todd L. Veldhuizen. Five compilation models for C++ templates. In First Workshop on C++ Template Programming, October 10 2000.]]Google ScholarGoogle Scholar
  70. 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 ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Concepts: linguistic support for generic programming in C++

        Recommendations

        Comments

        Login options

        Check if you have access through your login credentials or your institution to get full access on this article.

        Sign in

        PDF Format

        View or Download as a PDF file.

        PDF

        eReader

        View online with eReader.

        eReader
        About Cookies On This Site

        We use cookies to ensure that we give you the best experience on our website.

        Learn more

        Got it!