70 likes | 83 Views
Programming with Concepts. What it means Slide 2 An example concept hierarchy: STL container concepts Slide 3 Concept refinement: stronger requirements enable more and better algorithms Slide 4 Extending STL concepts: the Matrix Template Library Slide 5
E N D
Programming with Concepts • What it means Slide 2 • An example concept hierarchy: STL container concepts Slide 3 • Concept refinement: stronger requirements enable more and better algorithms Slide 4 • Extending STL concepts: the Matrix Template Library Slide 5 • Extending STL concepts: the Boost Graph Library Slide 7
{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 Back 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, …
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. PairA. C. Front & BackInsertionSequence Set Multiset Map Multimap H. Set H. Multiset H. Map H. Multi-map Vector Slist Click on any node in the above concept hierarchy to see the corresponding requirements as specified in the SGI STL Programmer’s Guide List Deque See also http://www.sgi.com/tech/stl STL Container Concepts Container Back
STL Generic Algorithms on Forward Containers Requires input iterators Enables generic algorithms copy, for_each, equal, transform, … Back 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
Back 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
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 Back STL Concepts Container Iterator Algorithm Functor Adaptor See also http://www.osl.iu.edu/research/mtl/
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 … Back STL Concepts Container Iterator Algorithm Functor Adaptor See also http://www.boost.org/libs/graph/doc