Jim Fawcett CSE687 – Object Oriented Design Spring 2002

Slides:



Advertisements
Similar presentations
. STL: C++ Standard Library (continued). STL Iterators u Iterators are allow to traverse sequences u Methods  operator*  operator->  operator++, and.
Advertisements

Multimaps. Resources -- web For each new class, browse its methods These sites are richly linked, and contain indexes, examples, documents and other resources.
C++ Templates. What is a template? Templates are type-generic versions of functions and/or classes Template functions and template classes can be used.
C++ Sets and Multisets Set containers automatically sort their elements automatically. Multisets allow duplication of elements whereas sets do not. Usually,
. 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.
More on the STL vector list stack queue priority_queue.
Concept= a set of abstractions (e.g., types) (Generic Programming) Programming with Concepts defined by a set of requirements {vector, deque, list, set,
C++ Programming: Program Design Including Data Structures, Second Edition Chapter 22: Standard Template Library (STL)
Standard Template Library. Homework List HW will be posted on webpage Due Nov 15.
CMSC 202 Lesson 24 Iterators and STL Containers. Warmup Write the class definition for the templated Bag class – A bag has: Random insertion Random removal.
Data Structures Using C++1 Chapter 13 Standard Template Library (STL) II.
1 Iterators & Algorithms Iterators provide a link between containers and algorithms Example: We wish to write a function sum() that adds up the members.
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.
Writing Your Own STL Container Ray Lischner
STL Standard Template Library ● Good reference book: – The C++ Standard Library ● A Tutorial and Reference ● by Nicolai M. Josuttis ● 1999 – Addison Wesley.
Data Structures Using C++ 2E
C++ How to Program, 8/e © by Pearson Education, Inc. All Rights Reserved.
STL-Associative Containers. Associative Containers Sequence containers : "This is item 0, this is item 1, this is item 2…“ Associative containers : –
1 Today’s Objectives  Announcements The Final Exam will be on Monday, 31-Jul, at 6 p.m. – There is no alternate time and no makeup!  Intro to the Standard.
Dictionaries Collection of pairs.  (key, element)  Pairs have different keys  E.g. a pair contains two components, student id and name (1234, Nan)
Generic Programming Using the C++ Standard Template Library.
Data Structures Using C++ 2E Chapter 13 Standard Template Library (STL) II.
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)
CS 403, Class 23Slide #1 CS Programming Languages Class 23 November 16, 2000.
The Utility Class pair All associative containers make use of the pair template, which is defined in. Slightly stripped down, it looks basically like this:
CS212: Object Oriented Analysis and Design Lecture 24: Introduction to STL.
Lecture 8-3 : STL Algorithms. STL Algorithms The Standard Template Library not only contains container classes, but also algorithms that operate on sequence.
Computer Science and Software Engineering University of Wisconsin - Platteville 11.Standard Template Library Yan Shi CS/SE 2630 Lecture Notes.
STL – Standard Template Library L. Grewe. 2 Goals Lots of important algorithms, data structures in CS using Templates. is a software library partially.
1 Associative Containers Ordered Ordered Unordered UnorderedSets Maps as sets of pairs Set API Ex: Sieve of Eratosthenes Ex: Sieve of EratosthenesImplementation.
Copyright © 2009 – Curt Hill Standard Template Library An Introduction.
STL: Maps Jyh-Shing Roger Jang ( 張智星 ) CSIE Dept, National Taiwan University.
C++ Review STL CONTAINERS.
CSCI 383 Object-Oriented Programming & Design Lecture 25 Martin van Bommel.
STL Associative Containers navigating by key. Pair Class aggregates values of two, possibly different, types used in associative containers defined in.
Lecture 7-3 : STL Algorithms. STL Algorithms The Standard Template Library not only contains container classes, but also algorithms that operate on sequence.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Function Templates 16.2.
Object-Oriented Programming (OOP) Lecture No. 41
CS212: Object Oriented Analysis and Design
Regarding homework 9 Many low grades
Standard Template Library
Exceptions, Templates, and the Standard Template Library (STL)
Standard Template Library (STL)
Starting Out with C++ Early Objects Eighth Edition
Chapter 9 – Sets and Maps 9.1 Associative Container
Programming with Concepts
Algorithm Efficiency and Sorting
CS212: Object Oriented Analysis and Design
priority_queue<T>
CS212: Object Oriented Analysis and Design
Containers, Iterators, Algorithms, Thrust
Recitation Outline C++ STL associative containers Examples
Standard Template Library Model
Standard Version of Starting Out with C++, 4th Edition
Iterators and STL Containers
Exceptions, Templates, and the Standard Template Library (STL)
STL Библиотека стандартных шаблонов
Standard Template Library
Standard Template Library
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.
Generic Set Algorithms
Iterator Design Pattern Jim Fawcett CSE776 – Design Patterns Fall 2014
A dictionary lookup mechanism
Standard Template Library
Presentation transcript:

Jim Fawcett CSE687 – Object Oriented Design Spring 2002 STL Odds and Ends Jim Fawcett CSE687 – Object Oriented Design Spring 2002

Web References Dinkumware – author of Visual C++ library http://www.dinkumware.com/refxcpp.html Silicon Graphics Incorporated http://www.sgi.com/tech/stl/ Matrix Template Library http://citeseer.nj.nec.com/171850.html Rogue Wave STL Tutorial http://www.roguewave.com/support/docs/stdug/ MSKB STL Samples http://www.visionx.com/mfcpro/kbstl.htm University of Cambridge – C++ and the STL http://www-h.eng.cam.ac.uk/help/tpl/talks/C++.html

Removing Element Values To remove all values, t, from a vector, v, use: v.erase(remove(v.begin(),v.end(),t),v.end()); To remove all values, t, from a list, l, use: l.remove(t); // note: this remove is a member function To remove all values, t, from an associative container, c, use: c.erase(t); // remove corrupts an associative container

Finding and Counting Values What do you want to know? Algorithm to Use Member function to use Unsorted range Sorted Set or map Multiset or multimap Does the desired value exist? find binary_search count Does the desired value exist? If so, where is the first object with that value? equal_range or lower_bound Where is the first object with a value not preceding the desired value? find_if Where is the first object with a value succeeding the desired value? upper_bound How many objects have the desired value? Where are all the objects with the desired value? find (iteratively) Effective STL, Scott Meyers, Addison Wesley, 2001

Code Examples Inserter – demonstrates use of transform algorithm using an inserter iterator. Sorting – demonstrates use of sort, find_if, upper_bound, and lower_bound