- The STL
- STL Components
- Containers
- Iterators
- Generic Algorithms
- The Four Stages of STL Use
- The Standard Template Library (STL)
- Standard
- Part of any standards-compliant C++ compiler.
- Requires advanced features (default template values, for example).
- Some compilers (Microsoft Visual C++ 6.0, for example) can't hack
it.
- Include files don't end in
.h
.
- Everything's defined in the
std
namespace.
- Template
- Not a lot of object play involved.
- Templates give the STL its power, and make it hard to use.
- Subtle errors, humungous error messages.
- Library
- Actually just header files, no libraries involved.
- Six main components; three we'll spend a lot of time on, three we won't.
- The three main components are containers, iterators and generic
algorithms.
- A container is a data structure.
- An iterator references data in a container.
- A generic algorithm manipulates data referenced by iterators.
- The other three components.
- An adaptor changes the behavior of a component.
- There are adaptors for containers and iterators.
- A functor is an object that acts like a function.
- An allocator manages container storage.
- Containers separate into sequential and sorted associative containers.
- We'll be studying the vector and list sequential containers and the
map sorted associative container.
- A sequential container represents a sequence of values.
- Ordinary c++ arrays.
- STL vectors are dynamic arrays.
- Similar to pointers.
- More accurately called accessors.
- Relative to containers, unlike pointers.
- Iterators are the connective tissue between containers and generic algorithms.
- This is the basis of generic programming.
- The most important part of the STL.
- You can use the generic algorithms in the absence of anything else in
the STL.
- Look for
item
in the container part delimited by start
and end
.
- That's a linear search.
-
std::find(start, end, item)
- There are lots more.
- Denial.
- Why use that? I've got my own list class I can use.
- Acceptance.
- Oh, o.k. - I'll use maps. And maybe their list class isn't as buggy
as mine. But iterators are still stupid.
- Embrace.
- Hey, look at this: by putting this string into an istring stream, I
can pull off some istream iterators and use them in the copy algorithm to
back insert the words directly into a vector. Cool.
- Extend.
- Humm, maybe if I write an allocator that manages space in a disk
file, I can create persistent containers...
This page last modified on 3 February 2003.