Presentation is loading. Please wait.

Presentation is loading. Please wait.

Programming with Concepts

Similar presentations


Presentation on theme: "Programming with Concepts"— Presentation transcript:

1 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 11/10/2018

2 = Programming with Concepts
Back Generic Programming = Programming with Concepts Concept = set of abstractions (e.g., types) {vector<T>, deque<T>, list<T>, set<K>, map<K,T>, hash_set<K>, …} = defined by a set of requirements 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))). Container Concept e.g., in Standard Template Library (STL) generic algorithms algorithms that work correctly for every abstraction in a concept = and efficiently e.g., generic container algorithms: copy, for_each, equal, transform, accumulate, … 11/10/2018

3 See also http://www.sgi.com/tech/stl
STL Container Concepts Container Back Associative Container Sorted A. C. Unique A. C. Multiple A. C. Hashed A. C. Unique Sorted A. C. Multiple Sorted A. C. Unique Hashed A. C. Multiple Hashed A. C. Simple A. C. Pair A. C. Set Multiset H. Set H. Multiset H. Multi- map H. Map Map Multimap Front Insertion Sequence Back Insertion Sequence Random Access Container Forward Container Sequence Reversible Container List Vector Deque Front & Back Insertion Sequence Slist See also Click on any node in the above concept hierarchy to see the corresponding requirements as specified in the SGI STL Programmer’s Guide 11/10/2018

4 STL Generic Algorithms on Forward Containers
Requires input iterators Enables generic algorithms copy, for_each, equal, transform, … Back Container Requires forward iterators Forward Container Enables find, merge, fill, replace, generate, remove, unique, rotate, … Requires bidirectional iterators Enables reverse, partition, inplace_merge, … Sequence Reversible Container Front Insertion Sequence Back Insertion Sequence Requires random access iterators Enables sort, binary_search, random_shuffle, … Random Access Container Front & Back Insertion Sequence Vector Slist List Deque 11/10/2018

5 STL Concepts Back Container Iterator Algorithm Functor Adaptor
Forward Container Associative Container Input Iterator Output Iterator Input Algorithm Output Algorithm Unary Functor Binary Functor Iterator Adaptor Forward Iterator Forward Algorithm Binary Predicate Bidirectional Iterator Bidirectional Algorithm Order Relation Random Access Iterator Random Access Algorithm 11/10/2018

6 New Concepts in the Matrix Template Library
Back MTL Concepts STL Concepts Container Iterator Algorithm Functor Adaptor Matrix Sparse Dense Matrix Banded Matrix 2-D Iterator Matrix Algorithm Matrix Vector Algorithm Matrix Matrix Algorithm Iterator Adaptor Sparse Dense Scaled See also 11/10/2018

7 New Concepts in the Boost Graph Library
Back BGL Concepts STL Concepts Container Iterator Algorithm Functor Adaptor Graph Incidence Adj. Graph EdgeList Graph Graph Iterator Graph Algorithms Visitor BFS Visitor DFS Visitor Uniform Cost Visitor See also 11/10/2018


Download ppt "Programming with Concepts"

Similar presentations


Ads by Google