intro to the c++ stl timmie smith september 6, 2001

10
Intro to the C++ STL Timmie Smith September 6, 2001

Upload: shannon-griffith

Post on 18-Jan-2016

220 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Intro to the C++ STL Timmie Smith September 6, 2001

Intro to the C++ STL

Timmie Smith

September 6, 2001

Page 2: Intro to the C++ STL Timmie Smith September 6, 2001

What is the STL?

Standard Template Library A collection of classes to make C++

programming more efficient– Algorithms, Containers, and Iterators– Function objects, Allocators, and Adapters

Containers Containers

Function Objects

Iterators

Page 3: Intro to the C++ STL Timmie Smith September 6, 2001

STL Algorithms

Accept STL Iterators as arguments– Sort(begin, end);

4 categories– Non-modifying

For each, Find, Count, Equal, Search, etc.– Mutating

Copy, Generate, Reverse, Remove, Swap, etc.– Sorting Related

Sort, Stable sort, Binary search, Merge, etc.– Numeric

Accumulate, Inner product, Partial sum,Adjacent difference

Page 4: Intro to the C++ STL Timmie Smith September 6, 2001

STL Containers

Sequence Containers– Vectors, Linked Lists, and derivatives

Container Adaptors– Queue, Priority Queue, Stack

Associative Containers– Hash, Map, Set

Page 5: Intro to the C++ STL Timmie Smith September 6, 2001

STL Iterators

Used as arguments to algorithms Containers provide several iterators

– Begin, End, Reverse Begin, Reverse End

5 categories – each has specific operations– Input, Output, Forward, Bidirectional, Random

Input Operations: =, ==, !=, *, ->, ++ , No assignment of *iOutput Operations: =, *, ++

Forward Operations: =, ==, !=, *, ->, ++Bidirectional Operations: =, ==, !=, *, ->, ++, --

Random Operations: =, ==, !=, +=, -=, *, ->, +, ++, -, --, [n], <, <=, >, >=

Page 6: Intro to the C++ STL Timmie Smith September 6, 2001

Function Objects

Used by some algorithms– Applied to each element in input by For each– Used to create new elements by Generate

Predicates - Function Objects that return bool– Unary and Binary predicates used to test equality– Find If uses unary, Sort uses binary

Page 7: Intro to the C++ STL Timmie Smith September 6, 2001

Example Program

Page 8: Intro to the C++ STL Timmie Smith September 6, 2001

STL Summary

STL allows programmers to focus on application specific issues– Provides collections of algorithms, containers,

iterators, and other objects– Programmers don’t reinvent the wheel

STL has been parallelized by the Standard Template Adaptive Parallel Library (STAPL) project

Page 9: Intro to the C++ STL Timmie Smith September 6, 2001

STAPL Overview

STAPL provides parallel equivalents of the STL components– pAlgorithms are parallel STL algorithms– pContainers are parallel STL containers– pRanges are parallel extensions of STL iterators

STAPL is a superset of the STL– STL is used by STAPL– STAPL and STL can be used in the same program

Page 10: Intro to the C++ STL Timmie Smith September 6, 2001

STAPL and STL Resources

http://www.sgi.com/tech/stl/ SGI’s STL reference documentation

http://blackwidowers.cs.tamu.edu/projects/staplThe STAPL project page. Includes pointers to other STL resources, STAPL documentation, and forums to discuss STL and STAPL problems.

– Register with the site so you can participate and get help

514F and 514G in the Bright building