did-you-know? rent-now

Amazon no longer offers textbook rentals. We do!

did-you-know? rent-now

Amazon no longer offers textbook rentals. We do!

We're the #1 textbook rental company. Let us show you why.

9780201309560

Generic Programming and the STL Using and Extending the C++ Standard Template Library

by
  • ISBN13:

    9780201309560

  • ISBN10:

    0201309564

  • Edition: 1st
  • Format: Paperback
  • Copyright: 1998-10-13
  • Publisher: Addison-Wesley Professional
  • Purchase Benefits
List Price: $59.99

Summary

Many programmers are unaware that C++ is more than an object-oriented language. C++ is also a language for generic programming, a methodology that can greatly enhance your ability to write efficient and reusable software components. Written by noted C++ authority Matthew H. Austern, Generic Programming and the STL introduces you to the generic programming paradigm and to the most important instance of that paradigm--the C++ Standard Template Library (STL). This book reveals that the STL is more than a set of convenient container classes: It is also an extensible framework for generic and interoperable components. Generic Programming and the STL explains the central ideas underlying generic programming--concepts, modeling, and refinement--and shows how these ideas lead to the fundamental concepts of the STL: iterators, containers, and function objects. In this way you will conceive the STL as a library of concepts rather than a library of specific functions and classes. You will learn its formal structure and be able to take full advantage of its potential power. This book enables you to: Extend the STL with your own library of portable and interoperable general-purpose components Create algorithms that are decoupled from the types and data structures they operate on, thus eliminating the need to rewrite basic algorithms and data structures Write more elegant, efficient, and effective code that can be used and reused across platforms With the knowledge and understanding you will gain, you can achieve greater skill in creating the reusable and portable software that is now invaluable in our diverse and interconnected computing environment. 0201309564B04062001

Author Biography

Matthew H. Austern, PhD, studied at MIT and UC Berkeley. He now works in the Silicon Graphics compiler group, where he is one of the principal authors of SGI's implementation of the C++ Standard Template Library. Dr. Austern is also a contributor to Dr. Dobb's Journal and C++ Report, a moderator of the newsgroup comp.std.c++, and an active member of the ISO/ANSI C++ Standards Committee.

0201309564AB04062001

Table of Contents

Preface xv
Part I Introduction to Generic Programming 1(80)
Chapter 1 A Tour of the STL
3(6)
1.1 A Simple Example
3(4)
1.2 Summary
7(2)
Chapter 2 Algorithms and Ranges
9(24)
2.1 Linear Search
9(7)
2.1.1 Linear Search in C
10(2)
2.1.2 Ranges
12(1)
2.1.3 Linear Search in C++
13(3)
2.2 Concepts and Modeling
16(3)
2.3 Iterators
19(10)
2.3.1 Input Iterators
20(2)
2.3.2 Output Iterators
22(2)
2.3.3 Forward Iterators
24(3)
2.3.4 Bidirectional Iterators
27(1)
2.3.5 Random Access Iterators
28(1)
2.4 Refinement
29(2)
2.5 Summary
31(2)
Chapter 3 More about Iterators
33(16)
3.1 Iterator Traits and Associated Types
33(11)
3.1.1 Value Types
33(3)
3.1.2 Difference Type
36(1)
3.1.3 Reference and Pointer Types
37(1)
3.1.4 Dispatching Algorithms and Iterator Tags
38(3)
3.1.5 Putting It All Together
41(2)
3.1.6 Iterator Traits without iterator-traits
43(1)
3.2 Defining New Components
44(4)
3.2.1 Iterator Adaptors
46(1)
3.2.2 Advice for Defining an Iterator
47(1)
3.2.3 Advice for Defining an Algorithm
47(1)
3.3 Summary
48(1)
Chapter 4 Function Objects
49(10)
4.1 Generalizing Linear Search
49(3)
4.2 Function Object Concepts
52(4)
4.2.1 Unary and Binary Function Objects
52(1)
4.2.2 Predicates and Binary Predicates
53(1)
4.2.3 Associated Types
54(2)
4.3 Function Object Adaptors
56(2)
4.4 Predefined Function Objects
58(1)
4.5 Summary
58(1)
Chapter 5 Containers
59(22)
5.1 A Simple Container
59(8)
5.1.1 An Array Class
60(3)
5.1.2 How It Works
63(1)
5.1.3 Finishing Touches
63(4)
5.2 Container Concepts
67(5)
5.2.1 Containment of Elements
68(1)
5.2.2 Iterators
68(2)
5.2.3 The Hierarchy of Containers
70(1)
5.2.4 The Trivial Container
71(1)
5.3 Variable Size Container Concepts
72(6)
5.3.1 Sequences
73(2)
5.3.2 Associative Containers
75(3)
5.3.3 Allocators
78(1)
5.4 Summary
78(3)
5.4.1 Which Container Should You Use?
78(1)
5.4.2 Defining Your Own Container
79(2)
Part II Reference Manual: STL Concepts 81(92)
Chapter 6 Basic Concepts
83(8)
6.1 Assignable
83(1)
6.2 Default Constructible
84(1)
6.3 Equality Comparable
85(1)
6.4 Ordering
86(5)
6.4.1 LessThan Comparable
86(2)
6.4.2 Strict Weakly Comparable
88(3)
Chapter 7 Iterators
91(18)
7.1 Trivial Iterator
91(3)
7.2 Input Iterator
94(2)
7.3 Output Iterator
96(4)
7.4 Forward Iterator
100(2)
7.5 Bidirectional Iterator
102(1)
7.6 Random Access Iterator
103(6)
Chapter 8 Function Objects
109(16)
8.1 Basic Function Objects
110(3)
8.1.1 Generator
110(1)
8.1.2 Unary Function
111(1)
8.1.3 Binary Function
112(1)
8.2 Adaptable Function Objects
113(3)
8.2.1 Adaptable Generator
113(1)
8.2.2 Adaptable Unary Function
114(1)
8.2.3 Adaptable Binary Function
115(1)
8.3 Predicates
116(6)
8.3.1 Predicate
116(1)
8.3.2 Binary Predicate
117(1)
8.3.3 Adaptable Predicate
118(1)
8.3.4 Adaptable Binary Predicate
119(1)
8.3.5 Strict Weak Ordering
119(3)
8.4 Specialized Concepts
122(3)
8.4.1 Random Number Generator
122(1)
8.4.2 Hash Function
123(2)
Chapter 9 Containers
125(48)
9.1 General Container Concepts
125(11)
9.1.1 Container
125(6)
9.1.2 Forward Container
131(2)
9.1.3 Reversible Container
133(2)
9.1.4 Random Access Container
135(1)
9.2 Sequences
136(9)
9.2.1 Sequence
136(5)
9.2.2 Front Insertion Sequence
141(2)
9.2.3 Back Insertion Sequence
143(2)
9.3 Associative Containers
145(21)
9.3.1 Associative Container
145(4)
9.3.2 Unique Associative Container
149(3)
9.3.3 Multiple Associative Container
152(1)
9.3.4 Simple Associative Container
153(2)
9.3.5 Pair Associative Container
155(1)
9.3.6 Sorted Associative Container
156(5)
9.3.7 Hashed Associative Container
161(5)
9.4 Allocator
166(7)
Part III Reference Manual: Algorithms and Classes 173(342)
Chapter 10 Basic Components
175(24)
10.1 pair
175(2)
10.2 Iterator Primitives
177(10)
10.2.1 iterator_traits
177(2)
10.2.2 Iterator Tag Classes
179(2)
10.2.3 distance
181(2)
10.2.4 advance
183(2)
10.2.5 Iterator Base Class
185(2)
10.3 allocator
187(2)
10.4 Memory Management Primitives
189(7)
10.4.1 construct
189(1)
10.4.2 destroy
190(2)
10.4.3 uninitialized_copy
192(2)
10.4.4 uninitialized_fill
194(1)
10.4.5 uninitialized_fill_n
195(1)
10.5 Temporary Buffers
196(3)
10.5.1 get_temporary_buffer
197(1)
10.5.2 return_temporary_buffer
198(1)
Chapter 11 Nonmutating Algorithms
199(34)
11.1 Linear Search
199(7)
11.1.1 find
199(1)
11.1.2 find_if
200(2)
11.1.3 adjacent_find
202(2)
11.1.4 find_first_of
204(2)
11.2 Subsequence Matching
206(8)
11.2.1 search
206(3)
11.2.2 find_end
209(2)
11.2.3 search_n
211(3)
11.3 Counting Elements
214(4)
11.3.1 count
214(2)
11.3.2 count_if
216(2)
11.4 for_each
218(2)
11.5 Comparing Two Ranges
220(7)
11.5.1 equal
220(2)
11.5.2 mismatch
222(3)
11.5.3 lexicographical_compare
225(2)
11.6 Minimum and Maximum
227(6)
11.6.1 min
227(1)
11.6.2 max
228(1)
11.6.3 min_element
229(2)
11.6.4 max_element
231(2)
Chapter 12 Basic Mutating Algorithms
233(58)
12.1 Copying Ranges
233(4)
12.1.1 copy
233(3)
12.1.2 copy_backward
236(1)
12.2 Swapping Elements
237(3)
12.2.1 swap
237(1)
12.2.2 iter_swap
238(1)
12.2.3 swap_ranges
239(1)
12.3 transform
240(3)
12.4 Replacing Elements
243(6)
12.4.1 replace
243(1)
12.4.2 replace_if
244(2)
12.4.3 replace_copy
246(2)
12.4.4 replace_copy_if
248(1)
12.5 Filling Ranges
249(4)
12.5.1 fill
249(1)
12.5.2 fill_n
250(1)
12.5.3 generate
251(1)
12.5.4 generate_n
252(1)
12.6 Removing Elements
253(1)
12.6.1 remove
253(2)
12.6.2 remove_if
255(1)
12.6.3 remove_copy
256(2)
12.6.4 remove_copy_if
258(1)
12.6.5 unique
259(3)
12.6.6 unique_copy
262(2)
12.7 Permuting Algorithms
264(9)
12.7.1 reverse
264(1)
12.7.2 reverse_copy
265(1)
12.7.3 rotate
266(2)
12.7.4 rotate_copy
268(1)
12.7.5 next_permutation
269(2)
12.7.6 prev_permutation
271(2)
12.8 Partitions
273(2)
12.8.1 partition
273(1)
12.8.2 stable_partition
274(1)
12.9 Random Shuffling and Sampling
275(6)
12.9.1 random_shuffle
276(1)
12.9.2 random_sample
277(2)
12.9.3 random_sample_n
279(2)
12.10 Generalized Numeric Algorithms
281(10)
12.10.1 accumulate
281(2)
12.10.2 inner_product
283(2)
12.10.3 partial_sum
285(2)
12.10.4 adjacent_difference
287(4)
Chapter 13 Sorting and Searching
291(54)
13.1 Sorting Ranges
291(14)
13.1.1 sort
292(2)
13.1.2 stable_sort
294(3)
13.1.3 partial_sort
297(3)
13.1.4 partial_sort_copy
300(1)
13.1.5 nth_element
301(2)
13.1.6 is_sorted
303(2)
13.2 Operations on Sorted Ranges
305(31)
13.2.1 Binary Search
305(1)
13.2.1.1 binary_search
306(2)
13.2.1.2 lower_bound
308(2)
13.2.1.3 upper_bound
310(3)
13.2.1.4 equal_range
313(3)
13.2.2 Merging Two Sorted Ranges
316(1)
13.2.2.1 merge
316(2)
13.2.2.2 inplace_merge
318(2)
13.2.3 Set Operations on Sorted Ranges
320(1)
13.2.3.1 includes
321(3)
13.2.3.2 set_union
324(3)
13.2.3.3 set_intersection
327(3)
13.2.3.4 set_difference
330(3)
13.2.3.5 set_symmetric_difference
333(3)
13.3 Heap Operations
336(9)
13.3.1 make_heap
336(2)
13.3.2 push_heap
338(1)
13.3.3 pop_heap
339(3)
13.3.4 sort_heap
342(1)
13.3.5 is_heap
343(2)
Chapter 14 Iterator Classes
345(26)
14.1 Insert Iterators
345(9)
14.1.1 front_insert_iterator
345(3)
14.1.2 back_insert_iterator
348(3)
14.1.3 insert_iterator
351(3)
14.2 Stream Iterators
354(9)
14.2.1 istream_iterator
354(3)
14.2.2 ostream_iterator
357(2)
14.2.3 istreambuf_iterator
359(3)
14.2.4 ostreambuf_iterator
362(1)
14.3 reverse_iterator
363(5)
14.4 raw_storage_iterator
368(3)
Chapter 15 Function Object Classes
371(64)
15.1 Function Object Base Classes
371(2)
15.1.1 unary_function
371(1)
15.1.2 binary_function
372(1)
15.2 Arithmetic Operations
373(9)
15.2.1 plus
373(2)
15.2.2 minus
375(1)
15.2.3 multiplies
376(2)
15.2.4 divides
378(1)
15.2.5 modulus
379(1)
15.2.6 negate
380(2)
15.3 Comparisons
382(8)
15.3.1 equal_to
382(1)
15.3.2 not_equal_to
383(1)
15.3.3 less
384(2)
15.3.4 greater
386(1)
15.3.5 less_equal
387(1)
15.3.6 greater_equal
388(2)
15.4 Logical Operations
390(4)
15.4.1 logical_and
390(1)
15.4.2 logical_or
391(2)
15.4.3 logical_not
393(1)
15.5 Identity and Projection
394(6)
15.5.1 identity
394(1)
15.5.2 projectlst
395(2)
15.5.3 project2nd
397(1)
15.5.4 select1st
398(1)
15.5.5 select2nd
399(1)
15.6 Specialized Function Objects
400(3)
15.6.1 hash
400(2)
15.6.2 subtractive_rng
402(1)
15.7 Member Function Adaptors
403(18)
15.7.1 mem_fun_t
404(2)
15.7.2 mem_fun_ref_t
406(2)
15.7.3 mem_fun1_t
408(2)
15.7.4 mem_fun1_ref_t
410(2)
15.7.5 const_mem_fun_t
412(2)
15.7.6 const_mem_fun_ref_t
414(2)
15.7.7 const_mem_fun1_t
416(2)
15.7.8 const_mem_fun1_ref_t
418(3)
15.8 Other Adaptors
421(14)
15.8.1 binder1st
421(1)
15.8.2 binder2nd
422(2)
15.8.3 pointer_to_unary_function
424(2)
15.8.4 pointer_to_binary_function
426(2)
15.8.5 unary_negate
428(1)
15.8.6 binary_negate
429(2)
15.8.7 unary_compose
431(2)
15.8.8 binary_compose
433(2)
Chapter 16 Container Classes
435(80)
16.1 Sequences
435(25)
16.1.1 vector
435(6)
16.1.2 list
441(7)
16.1.3 slist
448(7)
16.1.4 deque
455(5)
16.2 Associative Containers
460(44)
16.2.1 set
461(5)
16.2.2 map
466(7)
16.2.3 multiset
473(5)
16.2.4 multimap
478(6)
16.2.5 hash_set
484(4)
16.2.6 hash_map
488(6)
16.2.7 hash_multiset
494(5)
16.2.8 hash_multimap
499(5)
16.3 Container Adaptors
504(11)
16.3.1 stack
505(2)
16.3.2 queue
507(3)
16.3.3 priority_queue
510(5)
Appendix A Portability and Standardization
515(16)
A.1 Language Changes
516(8)
A.1.1 The Template Compilation Model
516(1)
A.1.2 Default Template Parameters
517(1)
A.1.3 Member Templates
518(1)
A.1.4 Partial Specialization
519(2)
A.1.5 New Keywords
521(3)
A.2 Library Changes
524(3)
A.2.1 Allocators
524(1)
A.2.2 Container Adaptors
525(1)
A.2.3 Minor Library Changes
526(1)
A.3 Naming and Packaging
527(4)
Bibliography 531(4)
Index 535

Supplemental Materials

What is included with this book?

The New copy of this book will include any supplemental materials advertised. Please check the title of the book to determine if it should include any access cards, study guides, lab manuals, CDs, etc.

The Used, Rental and eBook copies of this book are not guaranteed to include any supplemental materials. Typically, only the book itself is included. This is true even if the title states it includes any access cards, study guides, lab manuals, CDs, etc.

Excerpts

This is not a book about object-oriented programming.You may think that's odd. You probably found this book in the C++ section of the bookstore, after all, and you've probably heard people useobject orientedandC++ synonymously, but that isn't the only way to use the C++ language. C++ supports several fundamentally different paradigms, the newest and least familiar of which is generic programming.Like most new ideas, generic programming actually has a long history. Some of the early research papers on generic programming are nearly 25 years old, and the first experimental generic libraries were written not in C++ but in Ada MS89a, MS89b and Scheme KMS88. Yet generic programming is new enough that no textbooks on the subject exist.The first example of generic programming to become important outside of research groups was the STL, the C++ Standard Template Library. The Standard Template Library, designed by Alexander Stepanov (then of Hewlett-Packard Laboratories) and Meng Lee, was accepted in 1994 as part of the C++ standard library. The freely available "HP implementation" SL95, which served as a demonstration of the STL's capabilities, was released the same year.When the Standard Template Library first became part of the C++ standard, the C++ community immediately recognized it as a library of high-quality and efficient container classes. It is always easiest to see what is familiar, and every C++ programmer is familiar with container classes. Every nontrivial program requires some way of managing a collection of objects, and every C++ programmer has written a class that implements strings or vectors or lists.Container class libraries have been available since the earliest days of C++, and when "template" classes (parameterized types) were added to the language, one of their first uses--indeed, one of the main reasons that templates were introduced--was parameterized container classes. Many different vendors, including Borland, Microsoft, Rogue Wave, and IBM, wrote their own libraries that included Array or its equivalent.The fact that container classes are so familiar made the STL seem at first to be nothing more than yet another container class library. This familiarity diverted attention from the ways in which the STL was unique.The STL is a large and extensible body of efficient, generic, and interoperable software components. It includes many of the basic algorithms and data structures of computer science, and it is written so that algorithms and data structures are decoupled from each other. Rather than a container class library, it is more accurate to think of the STL as a library of generic algorithms; containers exist so that the algorithms have something to operate on.You can use the existing STL algorithms in your programs, just as you can use the existing STL containers. For example, you can use the generic STL sort as you would use the function qsort from the standard C library (although sort is simpler, more flexible, safer, and more efficient). Several books, including David Musser and Atul Saini'sSTL Tutorial and Reference GuideMS96 and Mark Nelson'sC++ Programmer's Guide to the Standard Template LibraryNel95, explain how to use the STL in such a way.Even this much is useful. It is always better to reuse code than to rewrite it, and you can reuse the existing STL algorithms in your own programs. This is still, however, only one aspect of the STL. The STL was designed to be extensible; that is, it was designed so that, just as the different STL components are interoperable with each other, they are also interoperable with components you write yourself. Using the STL effectively means extending it. Generic ProgrammingThe STL is not just a collection of useful components. Its other aspect, which is less widely recognized and understood, is that it is a f

Rewards Program