1 / 9

Generic Programming: Programming with Concepts

Generic Programming: Programming with Concepts. What is generic programming? The essence of the generic programming approach is concept development: systematic classification of computing components according to their formal requirements But what is a concept?.

samira
Télécharger la présentation

Generic Programming: Programming with Concepts

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Generic Programming: Programming with Concepts What is generic programming? • The essence of the generic programming approach is concept development: systematic classification of computing components according to their formal requirements • But what is a concept?

  2. {vector<T>, deque<T>, list<T>, set<K>, map<K,T> hash_set<K>,…} Definition: Container refines Basic-container;uses Input-iterator;introduces begin(containers) -> iterators, end(containers) -> iterators, size(containers) -> naturals, empty(containers) -> bool;requires (for c: containers) size(c) = size(range(c, begin(c), end(c))), empty(c) = (size(c) = 0), valid(range(c, begin(c), end(c))). e.g., = Container Concept Container Concept in Standard Template Library (STL) = algorithms that work correctly for every abstraction in a concept Generic Programming = Programming with Concepts Concept = set of abstractions (e.g., types) defined by a set of requirements generic algorithms and efficiently e.g., generic container algorithms: copy, for_each, equal, transform, accumulate, …

  3. STL Container Concepts Container AssociativeContainer ForwardContainer Sequence ReversibleContainer SortedA. C. UniqueA. C. MultipleA. C. HashedA. C. Front InsertionSequence BackInsertionSequence UniqueSortedA. C. MultipleSortedA. C. UniqueHashedA. C. MultipleHashedA. C. Random AccessContainer SimpleA. C. PairedA. C. Front & BackInsertionSequence Set Multiset Map Multimap H. Set H. Multiset H. Map H. Multi-map Vector Slist List Deque See also http://www.sgi.com/tech/stl

  4. STL Generic Algorithms on Forward Containers Requires input iterators Enables generic algorithms copy, for_each, equal, transform, … Container Requiresforward iterators … ForwardContainer Enables find, merge, fill, replace, generate, remove, unique, rotate, … Requiresbidirectional iterators Enables reverse, partition, inplace_merge, … Sequence ReversibleContainer Front InsertionSequence BackInsertionSequence Requiresrandom access iterators Enables sort, binary_search, random_shuffle, … Random AccessContainer Front & BackInsertionSequence Vector Slist List Deque

  5. STL Concepts Container Iterator Algorithm Functor Adaptor ForwardContainer AssociativeContainer Input Iterator Output Iterator Input Algorithm Output Algorithm Unary Functor BinaryFunctor Iterator Adaptor Forward Iterator Forward Algorithm BinaryPredicate Bidirectional Iterator Bidirectional Algorithm OrderRelation Random Access Iterator Random Access Algorithm

  6. New Concepts in the Matrix Template Library MTL Concepts Iterator Adaptor 2-D Iterator Matrix Algorithm Matrix Sparse Dense Scaled … DenseMatrix BandedMatrix Sparse Matrix … Matrix MatrixAlgorithm Matrix VectorAlgorithm STL Concepts Container Iterator Algorithm Functor Adaptor http://www.lsc.nd.edu/research/mtl

  7. New Concepts in the Boost Graph Library BGL Concepts Graph Iterator Graph Algorithms Visitor Graph Adj.Graph EdgeListGraph Incidence Graph … BFS Visitor DFSVisitor Uniform CostVisitor … STL Concepts Container Iterator Algorithm Functor Adaptor http://www.boost.org/libs/graph/doc

  8. How Should We Attempt to Design and ImplementGeneric Computing Concepts? • Best to work upwards from experience with real problems • Best to start with algorithms: what do they need for generality, correctness, and efficiency (as in STL, MTL, BGL, …)and, in advanced research, - reliability, - mobility, - real-time

  9. The Role of Performance • Need advances in way we specify and organize performance properties, in addition to functionality • Performance properties of components should be an integral part of concept requirements • Raw material for performance descriptions: analytically derived bounds empirically observed performance data

More Related