Skip to main content

Design of Concept Libraries for C++

  • Conference paper

Part of the book series: Lecture Notes in Computer Science ((LNPSE,volume 6940))

Abstract

We present a set of concepts (requirements on template arguments) for a large subset of the ISO C++ standard library. The goal of our work is twofold: to identify a minimal and useful set of concepts required to constrain the library’s generic algorithms and data structures and to gain insights into how best to support such concepts within C++. We start with the design of concepts rather than the design of supporting language features; the language design must be made to fit the concepts, rather than the other way around. A direct result of the experiment is the realization that to simply and elegantly support generic programming we need two kinds of abstractions: constraints are predicates on static properties of a type, and concepts are abstract specifications of an algorithm’s syntactic and semantic requirements. Constraints are necessary building blocks of concepts. Semantic properties are represented as axioms. We summarize our approach: concepts = constraints + axioms. This insight is leveraged to develop a library containing only 14 concepts that encompassing the functional, iterator, and algorithm components of the C++ Standard Library (the STL). The concepts are implemented as constraint classes and evaluated using Clang’s and GCC’s Standard Library test suites.

This is a preview of subscription content, log in via an institution.

Buying options

Chapter
USD   29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD   39.99
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD   54.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Learn about institutional subscriptions

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. Abrahams, D., Gurtovoy, A.: C++ Template Metaprogramming: Concepts, Tools, and Techniques from Boost and Beyond. C++ In-Depth. Addison Wesley (2004)

    Google Scholar 

  2. Austern, M.: Generic Programming and the STL: Using and Extending the C++ Standard Template Library, 7th edn. Addison-Welsey Longman, Boston (1998)

    Google Scholar 

  3. Austern, M., Stroustrup, B., Thorup, M., Wilkinson, J.: Untangling the Balancing and Searching of Balanced Binary Search Trees. Software: Practice and Experience 33(13), 1273–1298 (2003)

    Article  Google Scholar 

  4. Bagge, A.H., David, V., Haveraaen, M.: The Axioms Strike Back: Testing with Concepts and Axioms in C++. In: 8th International Conference on Generative Programming and Component Engineering (GPCE 2009), Denver, Colorado, pp. 15–24 (2010)

    Google Scholar 

  5. Becker, P.: Working Draft, Standard for the Programming Language C++. Tech. Rep. N2914, ISO/IEC JTC 1, Information Technology Subcommittee SC 22, Programming Language C++ (2009)

    Google Scholar 

  6. Bernardy, J.P., Jansson, P., Zalewski, M., Schupp, S., Priesnitz, A.: A Comparison of C++ Concepts and Haskell Type Classes. In: Workshop on Generic Programming (WGP 2008), Victoria, Canada, pp. 37–48 (2008)

    Google Scholar 

  7. Bernardy, J.-P., Jansson, P., Zalewski, M., Schupp, S.: Generic Programming with C++ Concepts and Haskell Type Classes–A Comparison. Journal of Functional Programming 20(3-4), 271–302 (2010)

    Article  MATH  Google Scholar 

  8. Bracha, G., Odersky, M., Stoutamire, D., Wadler, P.: Making the Future Safe for the Past: Adding Genericity to the Java Programming Language. In: 13th ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA 1998), Vancouver, Canada, pp. 183–200 (1998)

    Google Scholar 

  9. Davenport, J.H., Gianni, P.M., Trager, B.M.: Scratchpad’s View of Algebra II: A Categorical View of Factorization. In: International Symposium on Symbolic and Algebraic Computation (ISSAC 1991), Bonn, Germany, pp. 32–38 (1991)

    Google Scholar 

  10. Davenport, J.H., Sutor, R.S.: AXIOM: The Scientific Computation System. Springer (1992)

    Google Scholar 

  11. Davenport, J.H., Trager, B.M.: Scratchpad’s View of Algebra I: Basic Commutative Algebra. In: Miola, A. (ed.) DISCO 1990. LNCS, vol. 429, pp. 40–54. Springer, Heidelberg (1990)

    Chapter  Google Scholar 

  12. David, V.: Concepts as Syntactic Sugar. In: 9th International Working Conference on Source Code Analysis and Manipulation (SCAM 2009), Alberta, Canada, pp. 147–156 (2009)

    Google Scholar 

  13. Dehnert, J.C., Stepanov, A.: Fundamentals of Generic Programming. In: Jazayeri, M., Musser, D.R., Loos, R.G.K. (eds.) Dagstuhl Seminar 1998. LNCS, vol. 1766, pp. 1–11. Springer, Heidelberg (2000)

    Chapter  Google Scholar 

  14. Dos Reis, G.: Personal Communication (October 2010)

    Google Scholar 

  15. Dos Reis, G., Stroustrup, B.: Specifying C++ Concepts. In: 33rd Symposium on Principles of Programming Languages (POPL 2006), Charleston, South Carolina, pp. 295–308 (2006)

    Google Scholar 

  16. Dos Reis, G., Stroustrup, B., Merideth, A.: Axioms: Semantics Aspects of C++ Concepts. Tech. Rep. N2887, ISO/IEC JTC 1, Information Technology Subcommittee SC 22, Programming Language C++ (2009)

    Google Scholar 

  17. Gamma, E., Helm, R., Johnson, R., Vlissides, J.: Design Patterns Elements of Reusable Object-Oriented Software. Addison-Wesley (1994)

    Google Scholar 

  18. Garcia, R., Järvi, J., Lumsdaine, A., Siek, J., Willcock, J.: An Extended Comparative Study of Language Support for Generic Programming. Journal of Functional Programming 17, 145–205 (2007)

    Article  MATH  Google Scholar 

  19. Gregor, D.: ConceptGCC (2008), http://www.generic-programming.org/software/ConceptGCC/

  20. Gregor, D., Järvi, J., Siek, J., Stroustrup, B., Dos Reis, G., Lumsdaine, A.: Concepts: Linguistic Support for Generic Programming in C++. In: ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA 2006), Portland, Oregon, pp. 291–310 (2006)

    Google Scholar 

  21. Hewlett-Packard: Standard Template Library Programmer’s Guide (1994), http://www.sgi.com/tech/stl/index.html

  22. International Organization for Standards: International Standard ISO/IEC 14882. Programming Languages — C++ (2003)

    Google Scholar 

  23. Järvi, J., Willcock, J., Lumsdaine, A.: Concept-Controlled Polymorphism. In: Pfenning, F., Macko, M. (eds.) GPCE 2003. LNCS, vol. 2830, pp. 228–244. Springer, Heidelberg (2003)

    Chapter  Google Scholar 

  24. Jones, M.P.: Type Classes with Functional Dependencies. In: Smolka, G. (ed.) ESOP 2000. LNCS, vol. 1782, pp. 230–244. Springer, Heidelberg (2000)

    Chapter  Google Scholar 

  25. Kennedy, A., Syme, D.: Design and Implementation of Generics for the .NET Common Language Runtime. In: ACM SIGPLAN 2001 Conference on Programming Language Design and Implementation (PLDI 2001), Snowbird, Utah, pp. 1–12 (2001)

    Google Scholar 

  26. Meyer, B.: Eiffel: The Language. Prentice-Hall (1991)

    Google Scholar 

  27. Milner, R., Harper, R., MacQueen, D., Tofte, M.: The Definition of Standard ML - Revised. The MIT Press (1997)

    Google Scholar 

  28. Musser, D., Stepanov, A.: Algorithm-oriented Generic Libraries. Software: Practice and Experience 24(7), 623–642 (1994)

    Article  Google Scholar 

  29. Pirkelbauer, P., Dechev, D., Stroustrup, B.: Support for the Evolution of C++ Generic Functions. In: Malloy, B., Staab, S., van den Brand, M. (eds.) SLE 2010. LNCS, vol. 6563, pp. 123–142. Springer, Heidelberg (2011)

    Chapter  Google Scholar 

  30. Siek, J., Lee, L.-Q., Lumsdaine, A.: The Boost Graph Library: User Guide and Reference Manual. Addison-Wesley (2001)

    Google Scholar 

  31. Siek, J., Lumsdaine, A.: Concept Checking: Binding Parametric Polymorphism in C++. In: 1st Workshop on C++ Template Programming, Erfurt, Germany (2000)

    Google Scholar 

  32. Siek, J., Lumsdaine, A.: Essential Language Support for Generic Programming. In: ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI 2005), Chicago, Illinois, pp. 73–84 (2005)

    Google Scholar 

  33. Siek, J., Lumsdaine, A.: Language Requirements for Large-Scale Generic Libraries. In: Glück, R., Lowry, M. (eds.) GPCE 2005. LNCS, vol. 3676, pp. 405–421. Springer, Heidelberg (2005)

    Chapter  Google Scholar 

  34. Stepanov, A., McJones, P.: Elements of Programming. Addison Wesley, Boston (2009)

    Google Scholar 

  35. Stroustrup, B.: Parameterized Types for C++. Computing Systems 2(1), 55–85 (1989)

    Google Scholar 

  36. Stroustrup, B.: The Design and Evolution of C++. Addison-Wesley (1994)

    Google Scholar 

  37. Stroustrup, B.: ”New” Value Terminology (2010), http://www2.research.att.com/~bs/terminology.pdf

  38. Sutton, A.: Origin C++0x Libraries (2011), http://code.google.com/p/origin

  39. Sutton, A., Holeman, R., Maletic, J.I.: Identification of Idiom Usage in C++ Generic Libraries. In: 18th International Conference on Program Comprehension (ICPC 2010), Braga, Portugal, pp. 160–169 (2010)

    Google Scholar 

  40. Sutton, A., Maletic, J.I.: Automatically Identifying C++0x Concepts in Function Templates. In: 24th International Conference on Software Maintenance (ICSM 2004), Beijing, China, pp. 57–66 (2008)

    Google Scholar 

  41. Torgersen, M., Hansen, C.P., Ernst, E., von der Ahé, P., Bracha, G., Gafter, N.: Adding Wildcards to the Java Programming Language. In: ACM Symposium on Applied Computing, SAC 2004, Nicosia, Cyprus, pp. 1289–1296 (2004)

    Google Scholar 

  42. Veldhuizen, T.: Expression Templates. C++ Report 7(5), 26–31 (1995)

    Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2012 Springer-Verlag Berlin Heidelberg

About this paper

Cite this paper

Sutton, A., Stroustrup, B. (2012). Design of Concept Libraries for C++. In: Sloane, A., Aßmann, U. (eds) Software Language Engineering. SLE 2011. Lecture Notes in Computer Science, vol 6940. Springer, Berlin, Heidelberg. https://doi.org/10.1007/978-3-642-28830-2_6

Download citation

  • DOI: https://doi.org/10.1007/978-3-642-28830-2_6

  • Publisher Name: Springer, Berlin, Heidelberg

  • Print ISBN: 978-3-642-28829-6

  • Online ISBN: 978-3-642-28830-2

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics