Programming with Concepts

Slides:



Advertisements
Similar presentations
M The University Of Michigan Andrew M. Morgan EECS Lecture 22 Savitch Ch. 16 Intro To Standard Template Library STL Container Classes STL Iterators.
Advertisements

. STL: C++ Standard Library (continued). STL Iterators u Iterators are allow to traverse sequences u Methods  operator*  operator->  operator++, and.
C++ Sets and Multisets Set containers automatically sort their elements automatically. Multisets allow duplication of elements whereas sets do not. Usually,
Generic Programming in the STL and Beyond David R. Musser Rensselaer Polytechnic Institute.
. STL: C++ Standard Library. Main Ideas u General purpose: generic data structures & algorithms, templates u Flexibility: Allows for many combinations.
What is generic programming? The essence of the generic programming approach is concept development: systematic classification of computing components.
COMP 171 Data Structures and Algorithms Tutorial 1 Template and STL.
. The Standard C++ Library. 2 Main Ideas Purpose Flexibility Efficiency Simple & Uniform Interface.
Concept= a set of abstractions (e.g., types) (Generic Programming) Programming with Concepts defined by a set of requirements {vector, deque, list, set,
Quick Overview of STL STL = Standard Template Library Main concept : Container, Iterator Application : Linked list, Stack etc.
C++ Programming: Program Design Including Data Structures, Second Edition Chapter 22: Standard Template Library (STL)
Data Structures Using C++1 Chapter 13 Standard Template Library (STL) II.
. STL: C++ Standard Library. Main Ideas u General purpose: generic data structures & algorithms, templates u Flexibility: Allows for many combinations.
Generic programming starts with algorithms. Lift Minimal requirements: works with maximal family of types Concrete algorithm: requires specific data type.
. STL: C++ Standard Library (continued). STL Iterators u Iterators are allow to traverse sequences u Methods  operator*  operator->  operator++, and.
Standard Template Library C++ introduced both object-oriented ideas, as well as templates to C Templates are ways to write general code around objects.
Writing Your Own STL Container Ray Lischner
Data Structures Using C++ 2E
CNS  Sequences  vector,deque,list,(string),forward_list  Container Adapters  queue, stack, priority_queue  Associative Containers  set, unordered_set.
C++ How to Program, 8/e © by Pearson Education, Inc. All Rights Reserved.
Generic Programming Using the C++ Standard Template Library.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Standard Template Library (STL)
Data Structures Using C++ 2E Chapter 13 Standard Template Library (STL) II.
Review for Final Andy Wang Data Structures, Algorithms, and Generic Programming.
C++ STL CSCI 3110.
We can’t walk on water, Trinity Software computer simulation. but we can produce the.
Software Design 1.1 Tapestry classes -> STL l What’s the difference between tvector and vector  Safety and the kitchen sink What happens with t[21] on.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 22: Standard Template Library (STL)
CSE 332: C++ STL containers Review: C++ Standard Template Library (STL) The STL is a collection of related software elements –Containers Data structures:
1. The term STL stands for ? a) Simple Template Library b) Static Template Library c) Single Type Based Library d) Standard Template Library Answer : d.
Data Structures Using C++1 Chapter 4 Standard Template Library (STL)
Standard Template Library The Standard Template Library was recently added to standard C++. –The STL contains generic template classes. –The STL permits.
1 Iterators Good reference site:
CS 403, Class 23Slide #1 CS Programming Languages Class 23 November 16, 2000.
Computer Science and Software Engineering University of Wisconsin - Platteville 11.Standard Template Library Yan Shi CS/SE 2630 Lecture Notes.
CS 403: Programming Languages Lecture 24 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
Intro to the C++ STL Timmie Smith September 6, 2001.
Introduction The STL is a complex piece of software engineering that uses some of C++'s most sophisticated features STL provides an incredible amount.
C++ Review STL CONTAINERS.
CSCI 383 Object-Oriented Programming & Design Lecture 25 Martin van Bommel.
A recap of the STL and more containers Plus an intro to string and file input and output! Lecture 8.
Algorithms CNS 3370 Copyright 2003, Fresh Sources, Inc.
Unit VI.  C++ templates are a powerful mechanism for code reuse, as they enable the programmer to write code (classes as well as functions) that behaves.
1 The Standard Template Library The STL is a collection of Container classes These are class templates for containers. A container is an object that stores.
Final Exam Review COP4530.
Object-Oriented Programming (OOP) Lecture No. 41
CS212: Object Oriented Analysis and Design
COP 3530 Data Structures & Algorithms
STL – Standard Template Library
Standard Template Library (STL)
Starting Out with C++ Early Objects Eighth Edition
Prof. Michael Neary Lecture 7: The STL Prof. Michael Neary
Chapter 22: Standard Template Library (STL)
CS212: Object Oriented Analysis and Design
Final Exam Review COP4530.
Generic Programming Karl Lieberherr 12/1/2018 Generic Programming.
priority_queue<T>
Containers, Iterators, Algorithms, Thrust
Templates. Templates Example: Swap Template Mechanism.
Elements are always copied when they are put into a container
Design Patterns Difficult to describe abstractly Elements:
Standard Version of Starting Out with C++, 4th Edition
Exceptions, Templates, and the Standard Template Library (STL)
STL Библиотека стандартных шаблонов
Standard Template Library
Standard Template Library
Jim Fawcett CSE687 – Object Oriented Design Spring 2002
Jim Fawcett CSE687 – Object Oriented Design Spring 2002
Some Definitions vector, string, deque, and list are standard sequence containers. set, multiset, map, multimap, unordered_set, unordered_multiset, unordered_map.
Standard Template Library
Presentation transcript:

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

= 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

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 http://www.sgi.com/tech/stl 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

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

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

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 http://www.osl.iu.edu/research/mtl/ 11/10/2018

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 http://www.boost.org/libs/graph/doc 11/10/2018