Stl Tutorial and Reference Guide: C++ Programming With the Standard Template Library

by ; ;
Edition: 2nd
Format: Hardcover
Pub. Date: 2001-01-01
Publisher(s): Addison-Wesley Professional
  • Free Shipping Icon

    This Item Qualifies for Free Shipping!*

    *Excludes marketplace orders.

List Price: $62.99

Rent Textbook

Select for Price
There was a problem. Please try again later.

New Textbook

We're Sorry
Sold Out

Used Textbook

We're Sorry
Sold Out

eTextbook

We're Sorry
Not Available

How Marketplace Works:

  • This item is offered by an independent seller and not shipped from our warehouse
  • Item details like edition and cover design may differ from our description; see seller's comments before ordering.
  • Sellers much confirm and ship within two business days; otherwise, the order will be cancelled and refunded.
  • Marketplace purchases cannot be returned to eCampus.com. Contact the seller directly for inquiries; if no response within two days, contact customer service.
  • Additional shipping costs apply to Marketplace purchases. Review shipping costs at checkout.

Summary

"The second edition is clearer and adds more examples on how to use STL in a practical environment. Moreover, it is more concerned with performance and tools for its measurement. Both changes are very welcome." --Lawrence Rauchwerger, Texas A&M University "So many algorithms, so little time! The generic algorithms chapter with so many more examples than in the previous edition is delightful! The examples work cumulatively to give a sense of comfortable competence with the algorithms, containers, and iterators used." --Max A. Lebow, Software Engineer, Unisys Corporation The STL Tutorial and Reference Guideis highly acclaimed as the most accessible, comprehensive, and practical introduction to the Standard Template Library (STL). Encompassing a set of C++ generic data structures and algorithms, STL provides reusable, interchangeable components adaptable to many different uses without sacrificing efficiency. Written by authors who have been instrumental in the creation and practical application of STL,STL Tutorial and Reference Guide, Second Editionincludes a tutorial, a thorough description of each element of the library, numerous sample applications, and a comprehensive reference. You will find in-depth explanations of iterators, generic algorithms, containers, function objects, and much more. Several larger, non-trivial applications demonstrate how to put STL's power and flexibility to work. This book will also show you how to integrate STL with object-oriented programming techniques. In addition, the comprehensive and detailed STL reference guide will be a constant and convenient companion as you learn to work with the library. This second edition is fully updated to reflect all of the changes made to STL for the final ANSI/ISO C++ language standard. It has been expanded with new chapters and appendices. Many new code examples throughout the book illustrate individual concepts and techniques, while larger sample programs demonstrate the use of the STL in real-world C++ software development. An accompanying Web site, including source code and examples referenced in the text, can be found at http://www.cs.rpi.edu/~musser/stl-book/index.html.

Author Biography

David R. Musser teaches at Rensselaer Polytechnic Institute. Gillmer J. Derge is President and CEO of Toltec Software Services, Inc., a consulting firm. Atul Saini is President and CEO of Fiorano Software Inc., a vendor of high-speed messaging middleware developed in C++.

Table of Contents

Foreword xxi
Foreword to the First Edition xxix
Preface xxxi
I Tutorial Introduction to STL 1(212)
Introduction
3(16)
Who Should Read This Book
4(1)
What Generic Programming Is and Why It's Important
4(3)
How C++ Templates Enable Generic Programming
7(8)
The ``Code Bloat'' Problem with Templates
15(1)
Understanding STL's Performance Guarantees
15(4)
Overview of STL Components
19(26)
Containers
19(7)
Generic Algorithms
26(7)
Iterators
33(3)
Function Objects
36(4)
Adaptors
40(3)
Allocators
43(2)
How STL Differs from Other Libraries
45(4)
Extensibility
46(1)
Component Interchangeability
46(2)
Algorithm/Container Compatibility
48(1)
Iterators
49(24)
Input Iterators
50(2)
Output Iterators
52(2)
Forward Iterators
54(1)
Bidirectional Iterators
55(1)
Random Access Iterators
56(2)
The STL Iterator Hierarchy: Combining Algorithms and Containers Efficiently
58(1)
Insert Iterators
59(3)
Revisiting Input and Output: Stream Iterators
62(2)
Specification of Iterator Categories Required by STL Algorithms
64(1)
Designing Generic Algorithms
65(2)
Why Some Algorithms Require More Powerful Iterators
67(1)
Choosing the Right Algorithm
68(1)
Constant Versus Mutable Iterator Types
68(3)
Iterator Categories Provided by STL Containers
71(2)
Generic Algorithms
73(54)
Basic Algorithm Organization in STL
73(4)
Nonmutating Sequence Algorithms
77(10)
Mutating Sequence Algorithms
87(15)
Sorting-Related Algorithms
102(20)
Generalized Numeric Algorithms
122(5)
Sequence Containers
127(34)
Vectors
129(19)
Deques
148(4)
Lists
152(9)
Sorted Associative Containers
161(22)
Sets and Multisets
162(12)
Maps and Multimaps
174(9)
Function Objects
183(10)
Passing Functions via Function Pointers
184(2)
Advantages of Specifying Function Objects with Template Parameters
186(5)
STL-Provided Function Objects
191(2)
Container Adaptors
193(8)
Stack Container Adaptor
194(2)
Queue Container Adaptor
196(2)
Priority Queue Container Adaptor
198(3)
Iterator Adaptors
201(4)
Function Adaptors
205(8)
Binders
205(1)
Negators
206(2)
Adaptors for Pointers to Functions
208(5)
II Putting It Together: Example Programs 213(80)
Program for Searching a Dictionary
215(10)
Finding Anagrams of a Given Word
215(3)
Interacting with the Standard String and I/O Streams Classes
218(2)
Generating Permutations and Searching the Dictionary
220(1)
Complete Program
221(2)
How Fast Is It?
223(2)
Program for Finding All Anagram Groups
225(10)
Finding Anagram Groups
225(1)
Defining a Data Structure to Work with STL
226(1)
Creating Function Objects for Comparisons
227(1)
Complete Anagram Group Finding Program
228(1)
Reading the Dictionary into a Vector of PS Objects
229(1)
Using a Comparison Object to Sort Word Pairs
230(1)
Using an Equality Predicate Object to Search for Adjacent Equal Elements
230(1)
Using a Function Adaptor to Obtain a Predicate Object
231(1)
Copying the Anagram Group to the Output Stream
232(1)
Output of the Anagram Program
232(3)
Better Anagram Program: Using the List and Map Containers
235(8)
Data Structure Holding Iterator Pairs
235(1)
Storing Information in a Map of Lists
236(1)
Outputting the Anagram Groups in Order of Size
237(1)
Better Anagram Program
238(1)
Output of the Program
239(1)
Why Use a Map Container?
240(3)
Faster Anagram Program: Using Multimaps
243(8)
Finding Anagram Groups, Version 3
243(3)
Declaration of the Multimap
246(1)
Reading the Dictionary into the Multimap
247(1)
Finding the Anagram Groups in the Multimap
247(2)
Outputting the Anagram Groups in Order of Size
249(1)
Output of the Program
249(1)
How Fast Is It?
250(1)
Defining an Iterator Class
251(8)
New Kind of Iterator: Counting Iterator
251(2)
Counting Iterator Class
253(6)
Combining STL with Object-Oriented Programming
259(8)
Using Inheritance and Virtual Functions
260(5)
Avoiding ``Code Bloat'' from Container Instances
265(2)
Program for Displaying Theoretical Computer Science Genealogy
267(12)
Sorting Students by Date
267(1)
Associating Students with Advisors
268(2)
Finding the Roots of the Tree
270(3)
Reading the File
273(2)
Printing the Results
275(1)
Complete ``Genealogy'' Program
276(3)
Class for Timing Generic Algorithms
279(14)
Obstacles to Accurate Timing of Algorithms
279(1)
Overcoming the Obstacles
280(3)
Refining the Approach
283(1)
Automated Analysis with a Timer Class
284(5)
Timing the STL Sort Algorithms
289(4)
III STL Reference Guide 293(166)
Iterator Reference Guide
295(24)
Input Iterator Requirements
296(2)
Output Iterator Requirements
298(1)
Forward Iterator Requirements
299(1)
Bidirectional Iterator Requirements
299(1)
Random Access Iterator Requirements
300(1)
Iterator Traits
301(3)
Iterator Operations
304(1)
Istream Iterators
304(3)
Ostream Iterators
307(2)
Reverse Iterators
309(4)
Back Insert Iterators
313(2)
Front Insert Iterators
315(1)
Insert Iterators
316(3)
Container Reference Guide
319(68)
Requirements
319(11)
Organization of the Container Class Descriptions
330(1)
Vector
331(8)
Deque
339(6)
List
345(9)
Set
354(6)
Multiset
360(5)
Map
365(8)
Multimap
373(5)
Stack Container Adaptor
378(2)
Queue Container Adaptor
380(3)
Priority Queue Container Adaptor
383(4)
Generic Algorithm Reference Guide
387(44)
Organization of the Algorithm Descriptions
387(2)
Nonmutating Sequence Algorithm Overview
389(1)
For Each
390(1)
Find
391(1)
Find First
391(1)
Adjacent Find
392(1)
Count
393(1)
Mismatch
394(1)
Equal
395(1)
Search
396(1)
Search N
397(1)
Find End
397(1)
Mutating Sequence Algorithm Overview
398(1)
Copy
399(1)
Swap
400(1)
Transform
401(1)
Replace
402(1)
Fill
403(1)
Generate
404(1)
Remove
404(2)
Unique
406(1)
Reverse
407(1)
Rotate
408(1)
Random Shuffle
408(1)
Partition
409(1)
Sorting-Related Algorithms Overview
410(2)
Sort
412(2)
Nth Element
414(1)
Binary Search
415(2)
Merge
417(1)
Set Operations on Sorted Structures
418(3)
Heap Operations
421(2)
Min and Max
423(1)
Lexicographical Comparison
424(1)
Permutation Generators
425(1)
Generalized Numeric Algorithms Overview
426(1)
Accumulate
427(1)
Inner Product
428(1)
Partial Sum
429(1)
Adjacent Difference
430(1)
Function Object and Function Adaptor Reference Guide
431(10)
Requirements
431(1)
Base Classes
432(1)
Arithmetic Operations
433(1)
Comparison Operations
433(1)
Logical Operations
434(1)
Negator Adaptors
435(1)
Binder Adaptors
435(1)
Adaptors for Pointers to Functions
436(1)
Adaptors for Pointers to Member Functions
437(4)
Allocator Reference Guide
441(14)
Introduction
441(1)
Allocator Requirements
442(3)
Default Allocator
445(3)
Custom Allocators
448(7)
Utilities Reference Guide
455(4)
Introduction
455(1)
Comparison Functions
455(1)
Pairs
456(3)
Appendix A STL Header Files 459(2)
Appendix B String Reference Guide 461(16)
B.1 String Classes
461(11)
B.2 Character Traits
472(5)
Appendix C STL Include Files Used in Example Programs 477(6)
C.1 Files Used in Example 17.1
477(6)
Appendix D STL Resources 483(2)
D.1 Internet Addresses for SGI Reference Implementation of STL
483(1)
D.2 World Wide Web Address for Source Code for Examples in this Book
483(1)
D.3 STL-Compatible Compilers
484(1)
D.4 Other Related STL and C++ Documents
484(1)
D.5 Generic Programming and STL Discussion List
484(1)
References 485(4)
Index 489

Excerpts

In the five years since the first edition of STL Tutorial and Reference Guide appeared, the C++ language standard has been finalized and officially accepted, C++ compiler vendors have made great progress in bringing their compilers into compliance with the standard, and dozens of other books and magazine articles have appeared that describe and explain the standardized language and libraries. Many of these books and articles have highlighted the Standard Template Library (STL) as the most significant addition to the standard. Some hailed it, as we did in this book''s first edition, as having the potential to revolutionize the way a large number of people program. The past five years have already seen much of that potential realized, with the first edition of this book playing a key role for tens of thousands of programmers. We wrote in the preface of the first edition that there are five reasons why the STL components could become some of the most widely used software in existence: C++ is becoming one of the most widely used programming languages (in large part due to the support it provides for building and using component libraries). Since STL has been incorporated into the ANSI/ISO standard for C++ and its libraries, compiler vendors are making it part of their standard distributions. All components in STL are generic, meaning that they are adaptable (by language-supported compile-time techniques) to many different uses. The generality of STL components has been achieved without sacrificing efficiency. The design of STL components as fine-grained, interchangeable building blocks makes them a suitable basis for further development of components for specialized areas such as databases, user interfaces, and so forth. We have enjoyed seeing these statements borne out by the developments of the past five years. Changes in the Second Edition In this new edition we have added substantially more tutorial material including expanded chapters in Part I on function objects and container, it- erator, and function adaptors, and two entirely new chapters in Part II containing substantial new examples. We have also gone through all example code and surrounding discussion, including the reference material in Part III, to bring them up to date with the final standard. (Although some ambiguities in the standard have been discovered since it was finalized, we believe that in most cases the remaining uncertainties about the meaning of STL component specifications have no important consequences for the practicing programmer. In the few cases where they might, we point them out.) We also added a new chapter in Part III describing utility components such as the pair and comparison classes, and a new appendix describing the STL-related features of the standard string class. In this edition we have also adopted the "literate programming" style for presenting example programs and code fragments. For readers unfamiliar with this approach to simultaneous programming and documenting, a brief explanation is given in Chapter 2 and more details are presented in Chapter 12. One benefit of the literate programming approach is that coding details can be presented once and then referred to (by name and page number) many times, so readers do not have to read through the same details repeatedly. Another major benefit is that we have been able check even more thoroughly than before that all code is syntactically and logically correct, since literate programming tools make it easy to extract the code directly from the manuscript and compile and test it. A list of the compilers the code has been compiled and tested with is given in Appendix D. Some History, from the Preface to the First Edition Virtually all C++ programmers know that this language was originated by one person, Bjarne Stroustrup, who began thinking of how to extend the C language to support definition of classes and objects as early as 1979. So too, the architecture of STL is largely the creation of one person, Alexander Stepanov. It is interesting that it was also in 1979, at about the same time as Stroustrup''s initial research, that Alex began working out his initial ideas of generic programming and exploring their potential for revolutionizing software development. Although Dave Musser had developed and advocated some aspects of generic programming as early as 1971, it was limited to a rather specialized area of software development (computer algebra). Alex recognized the full potential for generic programming and persuaded his then-colleagues at General Electric Research and Development (including, primarily, Dave Musser and Deepak Kapur) that generic programming should be pursued as a comprehensive basis for software development. But at that time there was no real support in any programming language for generic programming. The first major language to provide such support was Ada, with its generic units feature, and by 1987 Dave and Alex had developed and published an Ada library for list processing that embodied the results of much of their research on generic programming. However, Ada had not achieved much acceptance outside the defense industry, and C++ seemed more likely to become widely used and provide good support for generic programming, even though the language was relatively immature (it did not even have templates, added only later). Another reason for turning to C++, which Alex recognized early on, was that the C/C++ model of computation, which allows very flexible access to storage (via pointers), is crucial to achieving generality without losing efficiency. Still, much research and experimentation were needed, not just to develop individual components, but more important to develop an overall ar- chitecture for a component library based on generic programming. First at AT&T Bell Laboratories and later at Hewlett-Packard Research Labs, Alex experimented with many architectural and algorithm formulations, first in C and later in C++. Dave Musser collaborated in this research, and in 1992 Meng Lee joined Alex''s project at HP and became a major contributor. This work undoubtedly would have continued for some time as just a research project or at best would have resulted in an HP proprietary library, if Andrew Koenig of Bell Labs had not become aware of the work and asked Alex to present the main ideas at a November 1993 meeting of the ANSI/ISO committee for C++ standardization. The committee''s response was overwhelmingly favorable and led to a request from Andy for a formal proposal in time for the March 1994 meeting. Despite the tremendous time pressure, Alex and Meng were able to produce a draft proposal that received preliminary approval at that meeting. The committee had several requests for changes and extensions (some of them major), and a small group of committee members met with Alex and Meng to help work out the details. The requirements for the most significant extension (associative containers) had to be shown to be consistent by fully implementing them, a task Alex delegated to Dave Musser. It would have been quite easy for the whole enterprise to spin out of control at this point, but again Alex and Meng met the challenge and produced a proposal that received final approval at the July 1994 ANSI/ISO committee meeting. (Additional details of this history can be found in an interview Alex gave in the March 1995 issue of Dr. Dobb''s Journal.) Spreading the Word Subsequently, the Stepanov and Lee document 17 was incorporated into the ANSI/ISO C++ draft standard (1, parts of clauses 17 through 27). It also influenced other parts of the C++ Standard Library, such as the string facilities, and some of the previously adopted standards in those areas were revised accordingly. In spite of STL''s success with the committee, there remained the question of

An electronic version of this book is available through VitalSource.

This book is viewable on PC, Mac, iPhone, iPad, iPod Touch, and most smartphones.

By purchasing, you will be able to view this book online, as well as download it, for the chosen number of days.

Digital License

You are licensing a digital product for a set duration. Durations are set forth in the product description, with "Lifetime" typically meaning five (5) years of online access and permanent download to a supported device. All licenses are non-transferable.

More details can be found here.

A downloadable version of this book is available through the eCampus Reader or compatible Adobe readers.

Applications are available on iOS, Android, PC, Mac, and Windows Mobile platforms.

Please view the compatibility matrix prior to purchase.