100 likes | 229 Views
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. Function Objects. Iterators. Containers.
E N D
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 Function Objects Iterators Containers Containers
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
STL Containers • Sequence Containers • Vectors, Linked Lists, and derivatives • Container Adaptors • Queue, Priority Queue, Stack • Associative Containers • Hash, Map, Set
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 *i Output Operations: =, *, ++ Forward Operations: =, ==, !=, *, ->, ++ Bidirectional Operations: =, ==, !=, *, ->, ++, -- Random Operations: =, ==, !=, +=, -=, *, ->, +, ++, -, --, [n], <, <=, >, >=
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
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
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
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