9
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? Generic Programming: Programming with Concepts

Generic Programming: Programming with Concepts

  • Upload
    samira

  • View
    63

  • Download
    0

Embed Size (px)

DESCRIPTION

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?. - PowerPoint PPT Presentation

Citation preview

Page 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?

Generic Programming:

Programming with Concepts

Page 2: Generic Programming:  Programming with Concepts

Concept = set of abstractions (e.g., types)

Generic Programming = Programming with Concepts

defined by a set of requirements

{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))).

generic algorithms algorithms that work correctly for every abstraction in a concept

=

e.g., generic container algorithms: copy, for_each, equal, transform, accumulate, …

and efficiently

Container Concept

e.g.,

Container Concept

in Standard Template Library (STL)

Page 3: Generic Programming:  Programming with Concepts

Container

ForwardContainer

Sequence

Front InsertionSequence

BackInsertionSequence

ReversibleContainer

Random AccessContainer

AssociativeContainer

List

Vector

Deque

Front & BackInsertionSequence

SortedA. C.

UniqueA. C.

MultipleA. C.

HashedA. C.

UniqueSortedA. C.

MultipleSortedA. C.

UniqueHashedA. C.

MultipleHashedA. C.

SimpleA. C.

PairedA. C.

Set Multiset H. Set

H. Multiset

H. Multi-map

H. Map

Map Multimap

Slist

STL Container Concepts

See also http://www.sgi.com/tech/stl

Page 4: Generic Programming:  Programming with Concepts

Container

ForwardContainer

Sequence

Front InsertionSequence

BackInsertionSequence

ReversibleContainer

Random AccessContainer

List

Vector

Deque

Front & BackInsertionSequence

Slist

STL Generic Algorithms on Forward Containers

Requires input iterators

Enables generic algorithms copy, for_each, equal, transform, …

Requiresforward iterators

Enables find, merge, fill, replace, generate, remove, unique, rotate, …

Requiresbidirectional iterators

Enables reverse, partition, inplace_merge, …

Requiresrandom access iterators

Enables sort, binary_search, random_shuffle, …

Page 5: Generic Programming:  Programming with Concepts

Container

ForwardContainer

AssociativeContainer

STL Concepts

Input Iterator

Output Iterator

Iterator

Forward Iterator

Bidirectional

Iterator

Random Access Iterator

Algorithm Functor Adaptor

Input Algorithm

Output Algorithm

Forward Algorithm

Bidirectional

Algorithm

Random Access Algorithm

Unary Functor

BinaryFunctor

BinaryPredicate

OrderRelation

IteratorAdaptor

Page 6: Generic Programming:  Programming with Concepts

MTL Concepts

STL Concepts

Container Iterator Algorithm Functor Adaptor

2-D Iterator

Matrix

SparseMatrix

DenseMatrix

BandedMatrix …

Iterator Adaptor

Sparse Dense Scaled …

New Concepts in the Matrix Template Library

http://www.lsc.nd.edu/research/mtl

Matrix Algorithm

Matrix VectorAlgorithm

Matrix MatrixAlgorithm

Page 7: Generic Programming:  Programming with Concepts

BGL Concepts

STL Concepts

Container Iterator Algorithm Functor Adaptor

Graph Iterator

Graph

IncidenceGraph

Adj.Graph

EdgeListGraph …

New Concepts in the Boost Graph Library

http://www.boost.org/libs/graph/doc

Graph Algorithms

Visitor

BFS Visitor

DFSVisitor

Uniform CostVisitor

Page 8: Generic Programming:  Programming with 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

How Should We Attempt to Design and Implement

Generic Computing Concepts?

Page 9: Generic Programming:  Programming with Concepts

• 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

The Role of Performance