Topic: C++ SIG: Saini on STL, Feb 24 && Summary of Stepanov on STL, Jan 27
Author: mcorcora@ix.netcom.com (Marian Corcoran)
Date: 19 Feb 1995 23:26:16 GMT Raw View
Please forward to others who may be interested:
C/C++ SIG OF SOFTWARE FORUM at University of California Extension
Santa Clara, CA
TOPIC: TECHNICAL ASPECTS AND KEY IDEAS OF THE STANDARD TEMPLATE LIBRARY
(STL)
- Key ideas behind STL
- Reasons for the power of STL
- STL iterators
- Defining a customized iterator class (time permitting)
NOTE: A free MODENA compiler of the STL and excellent tutorial will be
given away by a business card drawing.
SPEAKER: ATUL SAINI of MODENA
CEO and President of Modena Software, vendor of STL
and C++ test suites
Member, ANSI C++ Committee
Experience on optimizing compilers and libraries
at Kuck and Associates and HaL Computer Systems
Meets with Alexander Stepanov, creator of STL
For further technical info on talk contact 1-800-MODENA-1
Date: February 24, Friday, 6:15 to 8:15 p.m.
Place: University of California, Santa Cruz Extension
3120 De La Cruz Blvd., Santa Clara
Hwy 101 to Trimble, left on De La Cruz, left to first
driveway
For further info or to be placed on e-mailing list:
Marian Corcoran, M.S.C.S.
C/C++ SIG Chair, Member ANSI C++ Committee
(408) 973 - 1662
mcorcora@ix.netcom.com
Cost:: Free, no reservations required, open to all
Future Meetings (Fourth Friday of month, 6:15 - 8:15 p.m.)
Mar 24 Jerry Schwartz of Declarative Systems on Parsing Problems in
C++ (has applications in CASE tools and other software
working with C++ source code) To obtain his free software
via anonymous ftp, ftp.crl.com at /users/ro/jss/slice.Z
Apr 28 Michael Ball SUN Microsystems on Avoiding Re-Compilation of
Class Libraries
Location: UC Santa Cruz Extension, 3120 De La Cruz Blvd., Santa Clara
For further information on other Software Forum SIGs consult the WEB
pages
www.commerce.net/SoftwareForum
**************************************************************
Stepanov Speaks on Standard Template Library in C++, January 27, 1995
by Marian Corcoran && Jim Miller
C/C++ SIG Chair Software Forum Newsletter Editor
Some 200 people showed up for our first C/C++ SIG meeting to hear
Alexander Stepanov s presentation on his important contribution to the
C++ language. His Standard Template Library (STL) represents the
integration of reusable components involving generic algorithms and
data structures into the C++ language standard. The STL is a class
library consisting of stacks, queues, priority queues, sorts, searches,
sets, and more.
A graduate of Moscow State University, where he studied
mathematics, Stepanov s work and preparation for developing STL spanned
over two decades. His ideas on generic programming started in the late
1970 s when he was working at General Electric Research Center in New
York. He and his colleagues began working on a language called Tecton,
which let programmers describe algorithms connected with generic
structures. In 1983, he moved to Polytechnic Institute of Brooklyn,
where he built a library of generic components in a language called
Scheme. In 1987, he was hired by Bell Labs to work on libraries in C++.
However, at that time, C++ did not have templates which were necessary
for genericity. He moved to Hewlett Packard Laboratories in 1988.
Thereafter, with Meng Lee, he began work on what was to become the
Standard Template Library in C++.
Design Principles
The design principles which have guided STL include
- comprehensiveness (takes the best from APL, List, and C),
- extensibility, efficiency (with complexity guaranteed at the
interface level) and
- basis in the natural C/C++ machine model and fundamental programming
paradigm. STL makes important use of templates and pointers, built into
C++.
Components
According to Stepanov, components in the STL may be classified as
follows:
1. Containers manage or control a set of objects
2. Iterators allow for traversal through a container. The iterator may
be thought of a the glue that connects different containers with
different algorithms.
3. Algorithm are the computational process.
4. Function objects consist of both the algorithm and a state. C++
provides for some closure, i.e., data and procedure may be combined.
(This cannot be easily done in C).
5. Adaptors are used to change one interface into another
6. An Allocator contains the memory model. In STL, only one section
uses machine-related types and they are located in less than 20 lines of
code. The rest of STL does not have code related to the machine. This
makes portability easier because machine-specific instructions are in a
very small part of the program.
Iterators in STL
Stepanov gave the following example of a linear search in C, C++ and
C++/STL. The following C code finds an integer in an array or part of an
array:
int *find(int* first, int* last, int value) {
while (first != last && *first != value) ++first;
return first;
}
The following C++ code takes the above code (which is good) and finds a
generic value in a generic array:
template <class T>
T* find(T* first, T* last, T value) {
while (first != last && *first != value) ++first;
return first;
}
In STL, the linear search could work on an integer or a pointer for a
data base:
template <class InputIterator, class T>
InputIterator find(InputIterator first, InputIterator last, T value) {
while (first != last && *first != value) ++first;
return first;
}
InputIterator is one of the types of iterators in STL. It may only be
used to read (but not write) the elements in some data structure.
There are certain requirements for iterators involving equality,
inequality, copy constructor (must return an equal object),
dereferencing, and the ability to traverse ( i.e. ++ or -- ).
This excellent presentation was a first look at the design principles,
components and iterators of the STL. To learn more, attend our next
meeting or watch for our next newsletter article. Stepanov also listed
the following sources:
Stepanov and Lee, The Standard Template Library (by ftp)
the ftp site given was butler.hpl.hp.com
Andy Koenig s columns in Journal of Object Oriented Programming
October 1994 issue of C++ Report (articles by Stroustrup and Vilot)
Web site: http://www.cs.rpi.edu/~musser/stl.hml
Musser and Stepanov, Algorithm-oriented Generic Libraries, Software
- Practice
and Experience, July 1994.
Special thanks to those who reviewed the article and gave suggestions
for improvement.