skip to main content
10.1145/1133981.1134014acmconferencesArticle/Chapter ViewAbstractPublication PagespldiConference Proceedingsconference-collections
Article

Algorithm specialization in generic programming: challenges of constrained generics in C++

Published:11 June 2006Publication History

ABSTRACT

Generic 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 algorithms and to address other issues associated with unconstrained generics. To be as broadly applicable as possible, generic algorithms are defined with minimal requirements on their inputs. At the same time, to achieve a high degree of efficiency, generic algorithms may have multiple implementations that exploit features of specific classes of inputs. This process of algorithm specialization relies on non-local type information and conflicts directly with the local nature of modular type checking. In this paper, we review the design and implementation of our extensions for generic programming in C++, describe the issues of algorithm specialization and modular type checking in detail, and discuss the important design tradeoffs in trying to accomplish both.We present the particular design that we chose for our implementation, with the goal of hitting the sweet spot in this interesting design space.

References

  1. 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
  2. D. G. Bobrow, L. G. DeMichiel, R. P. Gabriel, S. E. Keene, G. Kicsales, and D. A. Moon. Common LISP Object System specification X3J13 document 88-002R. SIGPLAN Not., 23(SI):1--143, 1988.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Daniel G. Bobrow, Kenneth Kahn, Gregor Kiczales, Larry Masinter, Mark Stefik, and Frank Zdybel. CommonLoops: Merging Lisp and object-oriented programming. In OOPSLA '86: Conference proceedings on Object-oriented programming systems, languages and applications, pages 17--29, New York, NY, USA, 1986. ACM Press.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. 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, New York, NY, USA, September 2005. ACM Press.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. 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, New York, NY, USA, 2005. ACM Press.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. Craig Chambers. Object-oriented multi-methods in Cecil. In Ole Lehrmann Madsen, editor, Proceedings of the 6th European Conference on Object-Oriented Programming (ECOOP), volume 615 of Lecture Notes in Computer Science, pages 33--56, Berlin, Heidelberg, New York, Tokyo, 1992. Springer-Verlag.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. Craig Chambers. Predicate classes. In ECOOP'93 - Object-Oriented Programming, volume 707 of Lecture Notes in Computer Science, pages 268--296, 1993.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Craig Chambers and Gary T. Leavens. Typechecking and modules for multimethods. ACM Trans. Program. Lang. Syst., 17(6):805--843, 1995.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. Craig Chambers and the Cecil Group. The Cecil Language: Specification and Rationale, Version 3.1. University of Washington, Computer Science and Engineering, December 2002. http://www.cs.washington.edu/research/projects/cecil/.]]Google ScholarGoogle Scholar
  10. 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, New York, NY, USA, 2006. ACM Press.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. Michael D. Ernst, Crag Kaplan, and Craig Chambers. Predicate dispatching: A unified theory of dispatch. In ECOOP '98, volume 1445 of Lecture Notes in Computer Science, pages 186--211, New York, NY, 1998. Springer-Verlag.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. 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
  13. 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, New York, NY, USA, 2003. ACM Press.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. 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
  15. Douglas Gregor. ConceptGCC: Concept extensions for C++. http://www.osl.iu.edu/~dgregor/ConceptGCC, 2005.]]Google ScholarGoogle Scholar
  16. 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 SC 22, Programming Language C++, August 2005.]]Google ScholarGoogle Scholar
  17. International Organization for Standardization. ISO/IEC 14882:1998: Programming languages - C++. Geneva, Switzerland, September 1998.]]Google ScholarGoogle Scholar
  18. Jaakko Järvi, Jeremiah Willcock, and Andrew Lumsdaine. Conceptcontrolled polymorphism. In Frank Pfennig and Yannis Smaragdakis, editors, Generative Programming and Component Engineering, volume 2830 of LNCS, pages 228--244. Springer Verlag, September 2003.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. Jaakko Järvi, JeremiahWillcock, and Andrew Lumsdaine. Associated types and constraint propagation for mainstream object-oriented generics. In OOPSLA, October 2005.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. Mark P. Jones. Dictionary-free overloading by partial evaluation. In Partial Evaluation and Semantics-Based Program Manipulation, Orlando, Florida, June 1994 (Technical Report 94/9, Department of Computer Science, University of Melbourne), pages 107--117, 1994.]]Google ScholarGoogle Scholar
  21. Mark P. Jones. Qualified Types: Theory and Practice. Distinguished Dissertations in Computer Science. Cambridge University Press, 1994.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. Oleg Kiselyov. Dynamic dispatch on a class of a type. Haskell mailing list, March 2003. http://okmij.org/ftp/Haskell/types.html#class-based-dispatch.]]Google ScholarGoogle Scholar
  23. 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
  24. Mark Lillibridge. Translucent Sums: A Foundation for Higher-Order Module Systems. PhD thesis, Pittsburgh, PA, May 1997.]]Google ScholarGoogle Scholar
  25. Brian McNamara and Yannis Smaragdakis. Static interfaces in C++. In First Workshop on C++ Template Programming, October 2000.]]Google ScholarGoogle Scholar
  26. Bertrand Meyer. Eiffel: the Language. Prentice Hall, New York, NY, first edition, 1992.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. 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
  28. Microsoft Corporation. C# Version 2.0 Specification, March 2005 Draft, March 2005. http://msdn.microsoft.com/vcsharp/-programming/language.]]Google ScholarGoogle Scholar
  29. Todd Millstein and Craig Chambers. Modular statically typed multimethods. In Proceedings of the Thirteenth European Conference on Object-Oriented Programming (ECOOP'99), volume 1628 of Lecture Notes in Computer Science, pages 279--303, Lisbon, Portugal, June 1999. Springer Verlag.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. Todd Millstein, Mark Reay, and Craig Chambers. Relaxed MultiJava: balancing extensibility and modular typechecking. In OOPSLA'03: Proceedings of the 18th annual ACM SIGPLAN conference on Object-oriented programing, systems, languages, and applications, pages 224--240, New York, NY, USA, 2003. ACM Press.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. Robin Milner, Mads Tofte, and Robert Harper. The Definition of Standard ML. MIT Press, 1990.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. David A. Musser and Alexander A. Stepanov. Generic Programming. In Proceedings of International Symposium on Symbolic and Algebraic Computation, volume 358 of Lecture Notes in Computer Science, pages 13--25, Rome, Italy, 1989.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  33. Martin Odersky and al. An overview of the Scala programming language. Technical Report IC/2004/64, EPFL Lausanne, Switzerland, 2004.]]Google ScholarGoogle Scholar
  34. Martin Odersky and Matthias Zenger. Scalable component abstractions. SIGPLAN Not., 40(10):41--57, 2005.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  35. Simon Peyton Jones, Mark Jones, and Erik Meijer. Type classes: an exploration of the design space. In Proceedings of the Second Haskell Workshop, June 1997.]]Google ScholarGoogle Scholar
  36. Jeremy Siek. A Language for Generic Programming. PhD thesis, Indiana University, 2005.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  37. 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
  38. Jeremy Siek and Andrew Lumsdaine. A modern framework for portable high performance numerical linear algebra. In Modern Software Tools for Scientific Computing. Birkhäuser, 1999.]]Google ScholarGoogle Scholar
  39. Jeremy Siek and Andrew Lumsdaine. Concept checking: Binding parametric polymorphism in C++. In First Workshop on C++ Template Programming, October 2000.]]Google ScholarGoogle Scholar
  40. 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, New York, NY, USA, June 2005. ACM Press.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  41. Silicon Graphics, Inc. SGI Implementation of the Standard Template Library, 2004. http://www.sgi.com/tech/stl/.]]Google ScholarGoogle Scholar
  42. A. Stepanov and M. Lee. The Standard Template Library. Technical Report HPL-94-34(R.1), Hewlett-Packard Laboratories, April 1994. http://www.hpl.hp.com/techreports.]]Google ScholarGoogle Scholar
  43. Bjarne Stroustrup. Design and Evolution of C++. Addison-Wesley Longman Publishing Co., Inc., Boston, MA, USA, 1994.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  44. Bjarne Stroustrup. Concepts - a more abstract complement to type checking. Technical Report N1510=03-0093, ISO/IEC JTC 1, Information Technology, Subcommittee SC 22, Programming Language C++, October 2003. http://www.open-std.org/jtc1/sc22/wg21.]]Google ScholarGoogle Scholar
  45. 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 SC 22, Programming Language C++, October 2003. http://www.open-std.org/jtc1/sc22/wg21.]]Google ScholarGoogle Scholar
  46. Bjarne Stroustrup and Gabriel Dos Reis. A concept design (rev. 1). Technical Report N1782=05-0042, ISO/IEC JTC 1, Information Technology, Subcommittee SC 22, Programming Language C++, May 2005.]]Google ScholarGoogle Scholar
  47. The GHC Team. The Glorious Glasgow Haskell Compilation System User's Guide, version 6.4.1 edition. http://www.haskell.org/ghc/docs/latest/html/users guide/index.html.]]Google ScholarGoogle Scholar
  48. P. Wadler and S. Blott. How to make ad-hoc polymorphism less adhoc. In ACM Symposium on Principles of Programming Languages, pages 60--76. ACM, January 1989.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  49. Jörg Walter and Mathias Koch. Boost Basic Linear Algebra. Boost, 2002. www.boost.org/libs/numeric.]]Google ScholarGoogle Scholar

Index Terms

  1. Algorithm specialization in generic programming: challenges of constrained generics 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
      • Published in

        cover image ACM Conferences
        PLDI '06: Proceedings of the 27th ACM SIGPLAN Conference on Programming Language Design and Implementation
        June 2006
        438 pages
        ISBN:1595933204
        DOI:10.1145/1133981
        • cover image ACM SIGPLAN Notices
          ACM SIGPLAN Notices  Volume 41, Issue 6
          Proceedings of the 2006 PLDI Conference
          June 2006
          426 pages
          ISSN:0362-1340
          EISSN:1558-1160
          DOI:10.1145/1133255
          Issue’s Table of Contents

        Copyright © 2006 ACM

        Publisher

        Association for Computing Machinery

        New York, NY, United States

        Publication History

        • Published: 11 June 2006

        Permissions

        Request permissions about this article.

        Request Permissions

        Check for updates

        Qualifiers

        • Article

        Acceptance Rates

        Overall Acceptance Rate406of2,067submissions,20%

      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!