Example: dental hygienist

Design of Concept Libraries for C++ - Bjarne Stroustrup

Design of Concept Libraries for C++Andrew Sutton and Bjarne StroustrupTexas A&M UniversityDepartment of Computer Science and Engineering{asutton, present a set of concepts (requirements on template arguments)for a large subset of the ISO C++ standard library. The goal of our work istwofold: to identify a minimal and useful set of concepts required to constrainthe library s generic algorithms and data structures and to gain insights into howbest to support such concepts within C++. We start with the Design of conceptsrather than the Design of supporting language features; the language Design mustbe made to fit the concepts, rather than the other way around. A direct result ofthe experiment is the realization that to simply and elegantly support generic pro-gramming we need two kinds of abstractions:constraintsare predicates on staticproperties of a type, andconceptsare abstract specifications of an algorithm ssyntactic and semantic requirements.}

Design of Concept Libraries for C++ Andrew Sutton and Bjarne Stroustrup Texas A&M University Department of Computer Science and Engineering {asutton, bs}@cse.tamu.edu

Tags:

  Design, Concept, Libraries, Design of concept libraries for c

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Transcription of Design of Concept Libraries for C++ - Bjarne Stroustrup

1 Design of Concept Libraries for C++Andrew Sutton and Bjarne StroustrupTexas A&M UniversityDepartment of Computer Science and Engineering{asutton, present a set of concepts (requirements on template arguments)for a large subset of the ISO C++ standard library. The goal of our work istwofold: to identify a minimal and useful set of concepts required to constrainthe library s generic algorithms and data structures and to gain insights into howbest to support such concepts within C++. We start with the Design of conceptsrather than the Design of supporting language features; the language Design mustbe made to fit the concepts, rather than the other way around. A direct result ofthe experiment is the realization that to simply and elegantly support generic pro-gramming we need two kinds of abstractions:constraintsare predicates on staticproperties of a type, andconceptsare abstract specifications of an algorithm ssyntactic and semantic requirements.}

2 Constraints are necessary building blocksof concepts. Semantic properties are represented as axioms. We summarize ourapproach:concepts=constraints+axioms. This insight is leveraged to de-velop a library containing only 14 concepts that encompassing the functional,iterator, and algorithm components of the C++ Standard Library (the STL). Theconcepts are implemented as constraint classes and evaluated using Clang s andGCC s Standard Library test : Generic programming, concepts, constraints, axioms, C++.1 IntroductionConcepts (requirements on template arguments) are the central feature of C++ genericlibrary Design ; they define the terms in which a library s generic data structures andalgorithms are specified. Every working generic library is based on concepts.

3 Theseconcepts may be represented using specifically designed language features ( [15,20]), in requirements tables ( , [2,22]), as comments in the code, in Design documents( , [21]), or simply in the heads of programmers. However, without concepts (formalor informal), no generic code could example, a Matrix library that allows a user to supply element types must havea Concept of what operations can be used on its elements. In other words, the Matrix li-brary has a Concept of a number, which has a de facto definition in terms of operationsused in the library code. Interpretations of number can vary dramatically from libraryto library. Is a polynomial function a number ? Are numbers supposed to support divi-sion? Are operations on numbers supposed to be associative?

4 Regardless, every genericMatrix library has a number this work, we experiment with designs for concepts by trying to minimize thenumber of concepts required to constrain the generic algorithms and data structures ofa library. To do such experiments, we need ways to represent concepts in C++ code. Ourapproach is to use constraint classes, which allows us to experiment with different setsof concepts for a library without pre-judging the needs for specific language supportfeatures. Once we have experimented with the Design of concepts for several Libraries ,we expect our criteria for Concept Design and use to have matured to the point wherewe can confidently select among the reasonably well-understood language Design alter-natives. Language support should be determined by ideal usage patterns rather than theother way work in the development of Concept Libraries has resulted in the definitionof large numbers of concepts to constrain comparatively few generic components.

5 Forexample, the last version of the C++ Draft Standard to include concepts [5] defined130 concepts to constrain approximately 250 data structures and algorithms. Nearly2/3rds of that library s exported abstractions were Concept definitions. Out of the 130concepts, 108 relate are used to (directly or indirectly) express the functional, iterator,and algorithms parts of the standard library that we address here. In comparison, theElements of Programming (EoP) book [34] covers similar material with 52 conceptsfor about 180 different algorithms (just under 1/3rd).Obviously, not all of the concepts in either publication are equally abstract . ThatC++ Draft Standard includes about 30 concepts enumerating requirements on overload-able operator s alone and several metaprogramming-like concepts such EoP book lists many concepts that explore variations on a theme; invariants arestrengthened or weakened, operators are dropped, and definition spaces are these and similar designs of concepts, it has been concluded that writing a genericlibrary requires exhaustive enumeration of overloadable operations, conceptual supportfor template metaprogramming, and massive direct language support for , such conclusions are false.

6 Furthermore, they are obviously false. Theoverwhelming majority of generic Libraries , including the original version of STL, werewritten without language support for concepts and used without enforcement mecha-nisms. The authors of these Libraries did not consider some hundred different conceptsduring their development. Rather, the generic components of these Libraries were writ-ten to a small set of idealized argue that generic Libraries are defined in terms of small sets of abstract andintuitive concepts, and that an effective specification of concepts is the product of aniterative process that minimizes the number of concepts while maintaining expressiveand effective constraints. Ideal concepts are fundamental to their application domain( ,String,Number, andIterator), and consequently it is a rare achievement to find agenuine new one.

7 These abstract and intuitive concepts must not be lost in the detailsneeded to express them in code. Neither should the ease of learning and ease of useoffered by these concepts be compromised by an effort to minimize the constraints ofevery explore these ideas concretely, we develop a minimal Design of the concepts forthe STL that encompasses its functional, iterator, and algorithm Libraries . The resultingconcept library defines only 14 concepts, 94 fewer than originally proposed for the cor-responding parts of the C++ Standard Library. We leverage the results of the experimentand the experience gained to derive a novel perspective on concepts for the C++ pro-gramming language. Our approach reveals a distinct difference between requirementsthat represent domain abstractions and those that support their specification:conceptsandconstraints, respectively.

8 Concepts based on this distinction results in a conceptu-ally simpler and more modular validate the Design of the concepts by implementing them within the frameworkof a Concept emulation library for the Origin C++ Libraries [38]. The Libraries are im-plemented using the 2011 ISO C++ standard facilities. The concepts are then integratedinto the STL subset of Clang s libc++ and GCC s libstdc++ and checked against theirtest suites for results of this work yield several contributions to our knowledge of generic pro-gramming. First, we demonstrate that it is both feasible and desirable to experiment toseek a minimal conceptual specification for a generic library. Second, we demonstratethat distinguishing between concepts (as abstractions) and constraints (as static require-ments) is an effective way to achieve this goal.

9 Third, we identify semantic properties,axioms, as the key to practical discrimination of concepts from constraints. Finally, weprovide a simpler and easier to use specification of key parts of the ISO C++ Related WorkGeneric programming is rooted in the ability to specify code that will work with a va-riety of types. Every language supporting generic programming must address the issueof how to specify the interface between generically written code and the set of concretetypes on which it operates. Several comparative studies have been conducted in supportfor generic programming and type constraints [18]. These studies were leveraged tosupport the definition of concepts for C++ML relies onsignaturesto specify the interface of modules and constrain the typeparameters of functors [27].

10 Operations in the signature are matched against those de-fined by a structure to determine conformance. In Haskell,type classesdenote sets oftypes that can be used with same operations [24]. A type is made a member of thatset by explicitly declaring it aninstanceand implementing the requisite classes are used as constraints on type parameters in the signatures of polymor-phic functions. Similarities between Haskell type classes and C++ concepts have alsobeen explored [6, 7]. AXIOM categoriesare used to define the syntax and semanticsof algebraic domains [10]. The specification of algebraic structures helped motivate thedesign of its category system [9, 11]. Requirements on type parameters in Eiffel, Java,and C# are specified in terms of inherited interfaces.


Related search queries