|
T
his
is not a book about object-oriented programming." With this striking characterization,
Matthew Austern's
Generic Programming and the STL
begins. Moreover,
this is not a book about plain usage of the STL, either. In Austern's opinion,
"To use the STL is to extend it." Rather than demonstrating how to use
the STL containers and algorithms, the author aims to introduce the reader
to a novel programming paradigm?generic programming?of which the STL is
an example. He sees the STL not just as a collection of useful components,
which it is, but beyond that as an extensible framework of generic software
components. In this book, the STL is presented as a library of abstract
concepts. As readers, we gain an understanding of the ideas behind the
STL, which enables us to extend the framework and write our own STL-compliant
classes and algorithms.
What is generic programming
about? Every programming paradigm is based on a specific kind of abstraction
that distinguishes it from other paradigms. For instance, the abstraction
supported by most contemporary programming languages is that of a subroutine
(or procedure or function): You can use a subroutine without knowing anything
about its implementation. Another abstraction is that of abstract data
types: You can manipulate and even create values without depending on the
actual representation of the data; only the interface is important. Object-oriented
programming adds another layer of abstraction by supporting hierarchies
of polymorphic data types: You can refer to a value and manipulate it without
needing to specify its exact type. In this way you can write a single function
that will operate on a number of types within an inheritance hierarchy.
The new abstraction that characterizes
generic programming is that of a set of requirements on data types. You
can write general and reusable functions (more precisely: function templates)
that are independent of the data types they operate on. It is a technique
comparable to functions that operate on polymorphic types in an inheritance
hierarchy. The notion of type requirements comes into play with the template
language feature in C++. If you've been programming with templates, you
will have noticed that each time you define a template that takes a type
argument you make assumptions about the operations that the type must provide.
Most often, we do not formally specify the set of requirements to such
a template type argument, because C++ does not have any specific language
features to express such requirements on data types. And here the is book
most fascinating: It is the first publication we've seen that recognizes
the need for a systematic approach to template programming. A formalized
specification of type requirements?Austern calls them "concepts"?is important
for intense use of templates.
The STL is an example of the
generic programming paradigm. It is a collection of predefined class and
function templates, but it is also a collection of "concepts" that specify
how the STL components collaborate and how the STL can be extended. Without
doubt, this book is unique because of the approach it takes in describing
the STL in terms of "concepts." The plain use of STL containers and algorithms
is described elsewhere; all STL books published so far explain what the
predefined STL components have to offer. None of them provides much information
about the systematic specification of type requirements behind the STL.
This book takes the reader one step further. It describes all predefined
components in the STL, but it explains them as manifestations of the abstract
concepts. If you just want to use the predefined STL components, this is
not the optimal book for you. If you strive for a thorough understanding
of the STL and want to use it intensively and intend to extend it, you'll
find all necessary information here.
In sum: the reader will learn
a lot about the underlying concepts of the STL and will close the book
having gained valuable new insights into the nature of template programming
in general.
Angelika Langer
develops
and teaches classes on advanced C++, STL, multithreading, internationalization,
and Java. She has served on the ANSI/ISO C++ Committee since 1993.
Klaus
Kreft
is a software architect and consultant with more than a decade
of experience in industrial software development. He works for Siemens
Business Services in Germany. Langer and Kreft are working on a book about
standard C++ iostreams and locales and are columnists for
C++
Report
.
|