Home > Store > Programming > C/C++

C++ Standard Template Library, The

Register your product to gain access to bonus material or receive a coupon.

C++ Standard Template Library, The

Book

  • Your Price: $51.43
  • List Price: $60.50
  • Usually ships in 24 hours.

Description

  • Copyright 2001
  • Dimensions: K
  • Pages: 512
  • Edition: 1st
  • Book
  • ISBN-10: 0-13-437633-1
  • ISBN-13: 978-0-13-437633-2

With the ANSI/ISO C++ Standard Template Library (STL), C++ developers have a powerful toolset for maximizing productivity, software quality, and performance at the same time. STL provides both comprehensive sets of container classes and fundamental algorithms to go with them-a large, systematic, and efficient framework for C++ development. Now, in this long-awaited book, the creators of the C++ Standard Template Library explain it authoritatively and in depth. Each chapter of The C++ Standard Template Library covers one STL component, including:

  • Detailed background about the component and its uses
  • A thorough review of the relevant ANSI/ISO C++ standard
  • Practical techniques for using and implementing the component
  • Extensive sample code
  • Hands-on exercises

Appendices present lists of reserved names, a detailed glossary of terms and references, and how STL interfaces with the rest of the Standard C++ library.

Fully reflective of the final ANSI/ISO STL standard, The C++ Standard Template Library is the last word on all aspects of STL development for every experienced C++ programmer.

Sample Content

Downloadable Sample Chapter

Click here for a sample chapter for this book: 0134376331.pdf

Table of Contents



0. Introduction.

Background. Functional Description. Using STL. Implementing STL. Testing STL. Exercises.



1. Iterators.

Background. Functional Description. Using Iterators. Exercises.



2. <utility>.

Background. Functional Description. Using <utility>. Implementing <utility>. Testing <utility>. Exercises.



3. <iterator>.

Background. Functional Description. Using <iterator>. Implementing <iterator>. Testing <iterator>. Exercises.



4. <memory>.

Background. Functional Description. Using <memory>. Implementing <memory>. Testing <memory>. Exercise.



5. Algorithms.

Background. Functional Description. Using Algorithms. Exercises.



6. <algorithm>.

Background. Functional Description. Using <algorithm>. Implementing <algorithm>. Testing <algorithm>. Exercises.



7. <numeric>.

Background. Functional Description. Using <numeric>. Implementing <numeric>. Testing <numeric>. Exercises.



8. <functional>.

Background. Functional Description. Using <functional>. Implementing <functional>. Testing <functional>. Exercises.



9. Containers.

Background. Functional Description. Using Containers. Exercises.



10. <vector>.

Background. Functional Description. Using <vector>. Implementing <vector>. Testing <vector>. Exercises.



11. <list>.

Background. Functional Description. Using <list>. Implementing <list>. Testing <list>. Exercises.



12. <deque>.

Background. Functional Description. Using <deque>. Implementing <deque>. Testing <deque>. Exercises.



13. <set>.

Background. Functional Description. Using <set>. Implementing <set>. Testing <set>. Exercises.



14. <map>.

Background. Functional Description. Using <map>. Implementing <map>. Testing <map>. Exercises.



15. <stack>. Background. Functional Description. Using <stack>. Implementing <stack>. Testing <stack>. Exercises.


16. <queue>.

Background. Functional Description. Using <queue>. Implementing <queue>. Testing <queue>. Exercises.



Appendix A: Interfaces.


Appendix B: Terms.


Appendix C: References.


Index.

Preface

Preface

The Standard Template Library (or STL for short) is a major component of the library portion of the ANSI/ISO Standard for the programming language C++. It was developed at Hewlett-Packard Labs by Alexander Stepanov and Meng Lee (S&L95), based heavily on earlier work by Stepanov and David R. Musser of Rensselaer Polytechnic Institute. (See M&S87, M&S89, and M&S94. All citations are listed in Appendix C: References.) You will find this software package to be a most ambitious, and coherent, use of templates in C++. Indeed, STL has already begun to alter significantly the way many programmers write C++ code.

This book shows you how to use the template classes and functions of STL as mandated by the C++ Standard (clauses 20 and 23-26). We focus here on STL as a fairly self-contained subset of a larger library defined for Standard C++. That library is designed to work, in turn, with the library defined for ANSI/ISO Standard C (ANS89 and ISO90). Consequently, you can look on this book as a companion to two earlier works by P.J. Plauger, The Standard C Library (Pla92) and The Draft Standard C++ Library (Pla95). Taken together, these three books describe nearly all the library facilities of widespread interest to C++ programmers.

C++ Standard

The C++ Standard was formally approved in 1998 and should be stable for years to come. It is both an ANSI Standard (within the USA) and an ISO Standard (around the world). As part of the standardization process, the entire Standard C++ language and library were for the first time described completely and in one place. A relatively late event in that process was the incorporation of STL as part of the draft C++ Standard. More recent still is the wider dissemination of various implementations of Standard C++ compilers and libraries. Thus, much of what you will find in this book is news, even to experienced C++ programmers.

Similarly, the description of STL (precursors to S&L95) saw only limited circulation before its incorporation into the draft C++ Standard of July 1994. In the process of incorporation, it has been reorganized and changed in several significant ways. The STL in Standard C++ is not the package made widely available by Hewlett-Packard. It is not the version more recently enhanced by many different agencies. Thus, even programmers with early experience using STL can profit from this book. You will find here a complete presentation of STL as it is specified by the C++ Standard.

The book also shows you at least one way to implement STL. We present about 6,000 lines of tested, working code that is known to be portable across a number of C++ compilers. It is, in fact, essentially the same code that you will find distributed with Microsoft Visual C++, IBM Visual Age, as well as with C++ compilers offered by a number of other vendors. Minor changes have been made in formatting and notation, to make the book form of the code more readable and tutorial.

To a large extent, the code presented here works atop any C++ library. (See Appendix A: Interfaces.) It is designed to work particularly well, however, with a library that conforms closely to the C++ Standard. As much as possible, the code avoids forms that are non portable or not likely to be widely available. Code that relies on recent additions to the C++ language, such as template partial specialization, may still present problems with some compilers. You will find that commercial versions of this library indulge in various compromises to deal with such dialect issues.

One way or another, you can use the code presented here to gain valuable experience using a library of templates that is well on its way to becoming an important standard for the C++ world. Equally important, we believe that seeing a realistic implementation of STL can help you better under-stand how to use it.

And that introduces yet another goal. Besides presenting STL as standardized, and working code to implement it, this book also serves as a tutorial on how to use this library. You will find here useful background information on how the library came to take its present form, how it was meant to be used, and how it should be used. You don't have to read and understand all the code presented here to achieve that basic goal. Even a cursory study is beneficial. You certainly don't have to be a sophisticated user to profit from this book, but the programmer who is just an occasional sophisticate will find the information presented here invaluable.

Teaching you how to write C++ is not a goal of this book. We assume you know enough about C++ to read straightforward code. Where the code presented is not so straightforward, we explain the trickery involved.

extending STL

A final purpose of this book is to teach programmers how to design and implement extensions to the Standard Template Library. STL brings to-gether numerous algorithms, data structures, and programming tech-niques. It is not, however, intended to supply a complete set of facilities that a programmer might need. Rather, it provides a core of the most widely used facilities. And it describes the rules by which this core code is written. Once you learn to follow these rules, you can add your own algorithms that work with existing data structures. You can also add data structures that work with existing algorithms. Using the STL code presented here as an example, you will soon learn how to tackle new problems by writing a minimum of new code. And you will find that the new code is itself often reusable on future projects. That's what library design is all about, in the end.

structure of this book

The book is structured much like the STL code itself. The C++ Standard specifies numerous headers, but only thirteen of these headers define all the templates in STL. A separate chapter covers each header. Additional chapters introduce STL as a whole and discuss three overarching topics — iterators, algorithms, and containers. Most of the headers have reasonably cohesive contents. That makes for reasonably cohesive discussions. One or two, however, are catchalls. Their corresponding chapters are perforce wider ranging.

Each chapter that describes a header follows the same pattern. It begins with a brief background section, followed by a functional description of the header contents, then by suggestions for how best to use the facilities defined in the header. We then present the C++ code that constitutes the header itself, accompanied by a commentary on how the code works. We also present a small test program for each header, to provide at least a cursory example of how each template definition might be used.

Each chapter ends with a set of exercises. In a university course based on this book, the exercises can serve as homework problems. Many of them are simple exercises in using the library, or in code rewriting. They drive home a point or illustrate reasonable variations in implementation. The more ambitious exercises are labeled as such. They can serve as a basis for more extended projects. The independent reader can use the exercises as stimulus for further thought.

The Code

The code presented in this book and its description are based on the version of STL made widely available by Hewlett-Packard Company. That version contains the following notice:

Copyright (c) 1994 by Hewlett-Packard Company
Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation. Hewlett-Packard Company makes no representations about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty.

The code in this book has been tested, to various degrees, with C++ compilers from Microsoft, IBM, Edison Design Group, and Project GNU. It passes all the STL tests in the Dinkum C++ Proofer and the Dinkum Abridged Proofer, both quality-assurance tools for the corresponding libraries available commercially from Dinkumware, Ltd. It has also passed various versions of the commercial library validation suites available from Perennial Software and Plum Hall Inc. While we have taken pains to minimize errors, we cannot guarantee that none remain. Please note carefully the disclaimer on the copyright page.

Please note also that the code in this book is protected by copyright. It has not been placed in the public domain. Nor is it shareware. It is not protected by a "copy left" agreement, like code distributed by the Free Software Foundation (Project GNU). P.J. Plauger retains all rights. Dinkumware, Ltd. licenses it on a commercial basis.

The STL code that comes with a given C++ compiler may differ from the code presented here in various ways. This is true even of code based on that presented here. Dialects of C++ still abound, particularly in the complex area of template processing. Over time, all these dialects should converge, thanks to the completion of the C++ Standard. But for some time to come, you should consider the code presented here as reasonably representative of many implementations.

Updates

Submit Errata

More Information

Unlimited one-month access with your purchase
Free Safari Membership