Effective STL: 50 Specific Ways to Improve Your Use of the Standard Template Library
Scott Meyers

ISBN-10: 0201749629
ISBN-13: 9780201749625

Publisher: Addison-Wesley Professional
Copyright: 2001
Format: Paper; 288 pp
Published: 06/06/2001

Suggested retail price: $49.99
Buy from myPearsonStore

C++'s Standard Template Library is revolutionary, but learning to use it well has always been a challenge for students. In Effective STL, best-selling author Scott Meyers (Effective C++, More Effective C++) reveals the critical rules of thumb employed by the experts -- the things they almost always do or almost always avoid doing -- to get the most out of the library. This book offers clear, concise, and concrete guidelines to C++ programmers. While other books describe what's in the STL, Effective STL shows the student how to use it. Each of the book's 50 guidelines is backed by Meyers' legendary analysis and incisive examples, so the student will learn not only what to do, but also when to do it - and why.

Preface  xi

Acknowledgments  xv

Introduction  1

Chapter 1: Containers  11

Item 1: Choose your containers with care.  11

Item 2: Beware the illusion of container-independent code.  15

Item 3: Make copying cheap and correct for objects in containers.  20

Item 4: Call empty instead of checking size() against zero.  23

Item 5: Prefer range member functions to their single-element counterparts.  24

Item 6: Be alert for C++’s most vexing parse.  33

Item 7: When using containers of newed pointers, remember to delete the pointers before the container is destroyed.  36

Item 8: Never create containers of auto_ptrs.  40

Item 9: Choose carefully among erasing options.  43

Item 10: Be aware of allocator conventions and restrictions.  48

Item 11: Understand the legitimate uses of custom allocators.  54

Item 12: Have realistic expectations about the thread safety of STL containers.  58

Chapter 2: vector and string  63

Item 13: Prefer vector and string to dynamically allocated arrays.  63

Item 14: Use reserve to avoid unnecessary reallocations.  66

Item 15: Be aware of variations in string implementations.  68

Item 16: Know how to pass vector and string data to legacy APIs.  74

Item 17: Use “the swap trick” to trim excess capacity.  77

Item 18: Avoid using vector<bool>.  79

Chapter 3: Associative Containers  83

Item 19: Understand the difference between equality and equivalence.  83

Item 20: Specify comparison types for associative containers of pointers. 88

Item 21: Always have comparison functions return false for equal values.  92

Item 22: Avoid in-place key modification in set and multiset.  95

Item 23: Consider replacing associative containers with sorted vectors.  100

Item 24: Choose carefully between map::operator[] and map::insert when efficiency is important.   106

Item 25: Familiarize yourself with the nonstandard hashed containers.  111

Chapter 4: Iterators  116

Item 26: Prefer iterator to const_iterator, reverse_iterator, and const_reverse_iterator.  116

Item 27: Use distance and advance to convert const_iterators to iterators.   120

Item 28: Understand how to use a reverse_iterator’s base iterator.  123

Item 29: Consider istreambuf_iterators for character by character input.  126

Chapter 5: Algorithms  128

Item 30: Make sure destination ranges are big enough.  129

Item 31: Know your sorting options.  133

Item 32: Follow remove-like algorithms by erase if you really want to remove something.  139

Item 33: Be wary of remove-like algorithms on containers of pointers.  143

Item 34: Note which algorithms expect sorted ranges.  146

Item 35: Implement simple case-insensitive string comparisons via mismatch or lexicographical_compare.  150

Item 36: Understand the proper implementation of copy_if.  154

Item 37: Use accumulate or for_each to summarize ranges.  156

Chapter 6: Functors, Functor Classes, Functions, etc.  162

Item 38: Design functor classes for pass-by-value.  162

Item 39: Make predicates pure functions.  166

Item 40: Make functor classes adaptable.  169

Item 41: Understand the reasons for ptr_fun, mem_fun, and mem_fun_ref.  173

Item 42: Make sure less<T> means operator<.  177

Chapter 7: Programming with the STL  181

Item 43: Prefer algorithm calls to hand-written loops.  181

Item 44: Prefer member functions to algorithms with the same names.  190

Item 45: Distinguish among count, find, binary_search, lower_bound, upper_bound, and equal_range.  192

Item 46: Consider function objects instead of functions as algorithm parameters.  201

Item 47: Avoid producing write-only code.  206

Item 48: Always #include the proper headers.  209

Item 49: Learn to decipher STL-related compiler diagnostics.  210

Item 50: Familiarize yourself with STL-related web sites.  217

Bibliography  225

Appendix A: Locales and Case-Insensitive String Comparisons  229

Appendix B: Remarks on Microsoft’s STL Platforms  239

Index  245

Scott Meyers is one of the world's foremost authorities on C++, providing training and consulting services to clients worldwide. He is the author of the best-selling Effective C++ series of books (Effective C++, More Effective C++, and Effective STL) and of the innovative Effective C++ CD. He is consulting editor for Addison Wesley's Effective Software Development Series and serves on the Advisory Board for The C++ Source (http://www.artima.com/cppsource). He holds a Ph.D. in Computer Science from Brown University. His web site is http://www.aristeia.com.



“This is Effective C++ volume three – it’s really that good.”
– Herb Sutter, independent consultant and secretary of the ISO/ANSI C++ standards committee
“There are very few books which all C++ programmers must have. Add Effective STL to that list.”
– Thomas Becker, Senior Software Engineer, Zephyr Associates, Inc., and columnist, C/C++ Users Journal

C++’s Standard Template Library is revolutionary, but learning to use it well has always been a challenge. Until now. In this book, best-selling author Scott Meyers (Effective C++, and More Effective C++) reveals the critical rules of thumb employed by the experts – the things they almost always do or almost always avoid doing – to get the most out of the library.

Other books describe what’s in the STL. Effective STL shows you how to use it. Each of the book’s 50 guidelines is backed by Meyers’ legendary analysis and incisive examples, so you’ll learn not only what to do, but also when to do it – and why.

Highlights of Effective STL include:

  • Advice on choosing among standard STL containers (like vector and list), nonstandard STL containers (like hash_set and hash_map), and non-STL containers (like bitset).
  • Techniques to maximize the efficiency of the STL and the programs that use it.
  • Insights into the behavior of iterators, function objects, and allocators, including things you should not do.
  • Guidance for the proper use of algorithms and member functions whose names are the same (e.g., find), but whose actions differ in subtle (but important) ways.
  • Discussions of potential portability problems, including straightforward ways to avoid them.

Like Meyers’ previous books, Effective STL is filled with proven wisdom that comes only from experience. Its clear, concise, penetrating style makes it an essential resource for every STL programmer.

View a Sample Chapter PDF:

Pearson Higher Education offers special pricing when you choose to package your text with other student resources. If you're interested in creating a cost-saving package for your students, contact your Pearson Higher Education representative for pricing and ordering information.

This title is a member of the Addison-Wesley Professional Computing Series, which also contains the titles below . You can also visit the Addison-Wesley Professional Computing Series page.

  • 0201379279Advanced CORBA® Programming with C++
    Henning & Vinoski
    © 1999 | Addison-Wesley Professional | Paper; 1120 pages | Instock
    ISBN-10: 0201379279 | ISBN-13: 9780201379273
    Brief Description | Buy from myPearsonStore

  • 0321525949Advanced Programming in the UNIX Environment: Paperback Edition, 2/E
    Stevens & Rago
    © 2008 | Addison-Wesley Professional | Paper; 960 pages | Instock
    ISBN-10: 0321525949 | ISBN-13: 9780321525949
    Buy from myPearsonStore

  • 0201433079Advanced Programming in the UNIX® Environment, 2/E
    Stevens & Rago
    © 2005 | Addison-Wesley Professional | Cloth; 960 pages | Instock
    ISBN-10: 0201433079 | ISBN-13: 9780201433074
    Brief Description | Buy from myPearsonStore

  • 0131411543Advanced UNIX Programming, 2/E
    Rochkind
    © 2004 | Addison-Wesley Professional | Paper; 736 pages | Instock
    ISBN-10: 0131411543 | ISBN-13: 9780131411548
    Brief Description | Buy from myPearsonStore

  • 0131429019The Art of UNIX Programming
    Raymond
    © 2004 | Addison-Wesley Professional | Paper; 560 pages | Instock
    ISBN-10: 0131429019 | ISBN-13: 9780131429017
    Brief Description | Buy from myPearsonStore

  • 020172152XBuilding Secure Software: How to Avoid Security Problems the Right Way
    Viega & McGraw
    © 2002 | Addison-Wesley Professional | Cloth; 528 pages | Instock
    ISBN-10: 020172152X | ISBN-13: 9780201721522
    Brief Description | Buy from myPearsonStore

  • 0201498413C Interfaces and Implementations: Techniques for Creating Reusable Software
    Hanson
    © 1997 | Addison-Wesley Professional | Paper; 544 pages | Instock
    ISBN-10: 0201498413 | ISBN-13: 9780201498417
    Buy from myPearsonStore

  • 0201634988Design Patterns CD: Elements of Reusable Object-Oriented Software
    Gamma, Helm, Johnson & Vlissides
    © 1998 | Addison-Wesley Professional | CD-ROM Only; 2 pages | Instock
    ISBN-10: 0201634988 | ISBN-13: 9780201634983
    Brief Description | Buy from myPearsonStore

  • 0201633612Design Patterns: Elements of Reusable Object-Oriented Software
    Gamma, Helm, Johnson & Vlissides
    © 1995 | Addison-Wesley Professional | Cloth; 416 pages | Instock
    ISBN-10: 0201633612 | ISBN-13: 9780201633610
    Brief Description | Buy from myPearsonStore

  • 0321334876Effective C++: 55 Specific Ways to Improve Your Programs and Designs, 3/E
    Meyers
    © 2005 | Addison-Wesley Professional | Paper; 320 pages | Instock
    ISBN-10: 0321334876 | ISBN-13: 9780321334879
    Brief Description | Buy from myPearsonStore

  • 0201749629Effective STL: 50 Specific Ways to Improve Your Use of the Standard Template Library
    Meyers
    © 2001 | Addison-Wesley Professional | Paper; 288 pages | Instock
    ISBN-10: 0201749629 | ISBN-13: 9780201749625
    Brief Description | Buy from myPearsonStore

  • 020163466XFirewalls and Internet Security: Repelling the Wily Hacker, 2/E
    Cheswick, Bellovin & Rubin
    © 2003 | Addison-Wesley Professional | Paper; 464 pages | Instock
    ISBN-10: 020163466X | ISBN-13: 9780201634662
    Brief Description | Buy from myPearsonStore

  • 020163497XForensic Discovery
    Farmer & Venema
    © 2005 | Addison-Wesley Professional | Cloth; 240 pages | Instock
    ISBN-10: 020163497X | ISBN-13: 9780201634976
    Brief Description | Buy from myPearsonStore

  • 0321618092Forensic Discovery
    Farmer & Venema
    © 2005 | Addison-Wesley Professional | On-line Supplement | Estimated Availability: 12/27/2004
    ISBN-10: 0321618092 | ISBN-13: 9780321618092
    URL: http://safari.informit.com


  • 0201563339Gigabit Networking
    Partridge
    © 1994 | Addison-Wesley Professional | Paper; 416 pages | Estimated Availability: 10/30/1993
    ISBN-10: 0201563339 | ISBN-13: 9780201563337
    Brief Description | Buy from myPearsonStore

  • 0201634481Interconnections: Bridges, Routers, Switches, and Internetworking Protocols, 2/E
    Perlman
    © 2000 | Addison-Wesley Professional | Cloth; 560 pages | Instock
    ISBN-10: 0201634481 | ISBN-13: 9780201634488
    Buy from myPearsonStore

  • 0201633620Large-Scale C++ Software Design
    Lakos
    © 1996 | Addison-Wesley Professional | Paper; 896 pages | Instock
    ISBN-10: 0201633620 | ISBN-13: 9780201633627
    Buy from myPearsonStore

  • 020163371XMore Effective C++: 35 New Ways to Improve Your Programs and Designs
    Meyers
    © 1996 | Addison-Wesley Professional | Paper; 336 pages | Instock
    ISBN-10: 020163371X | ISBN-13: 9780201633719
    Buy from myPearsonStore

  • 020161586XThe Practice of Programming
    Kernighan & Pike
    © 1999 | Addison-Wesley Professional | Paper; 288 pages | Instock
    ISBN-10: 020161586X | ISBN-13: 9780201615869
    Brief Description | Buy from myPearsonStore

  • 0201379236STL Tutorial and Reference Guide: C++ Programming with the Standard Template Library, 2/E
    Musser, Derge & Saini
    © 2001 | Addison-Wesley Professional | Cloth; 560 pages | Instock
    ISBN-10: 0201379236 | ISBN-13: 9780201379235
    Brief Description | Buy from myPearsonStore

  • 0201633469TCP/IP Illustrated, Volume 1: The Protocols
    Stevens
    © 1994 | Addison-Wesley Professional | Cloth; 600 pages | Instock
    ISBN-10: 0201633469 | ISBN-13: 9780201633467
    Brief Description | Buy from myPearsonStore

  • 020163354XTCP/IP Illustrated, Volume 2: The Implementation
    Wright & Stevens
    © 1995 | Addison-Wesley Professional | Cloth; 1200 pages | Instock
    ISBN-10: 020163354X | ISBN-13: 9780201633542
    Brief Description | Buy from myPearsonStore

  • 0201634953TCP/IP Illustrated, Volume 3: TCP for Transactions, HTTP, NNTP, and the UNIX® Domain Protocols
    Stevens
    © 1996 | Addison-Wesley Professional | Cloth; 352 pages | Instock
    ISBN-10: 0201634953 | ISBN-13: 9780201634952
    Buy from myPearsonStore

  • 020163337XTcl and the Tk Toolkit
    Ousterhout
    © 1994 | Addison-Wesley Professional | Paper; 480 pages | Out of Stock
    ISBN-10: 020163337X | ISBN-13: 9780201633375
    Brief Description

  • 0201633388UNIX® Systems for Modern Architectures: Symmetric Multiprocessing and Caching for Kernel Programmers
    Schimmel
    © 1994 | Addison-Wesley Professional | Paper; 432 pages | Instock
    ISBN-10: 0201633388 | ISBN-13: 9780201633382
    Brief Description | Buy from myPearsonStore

  • 0131411551Unix Network Programming, Volume 1: The Sockets Networking API, 3/E
    Stevens, Fenner & Rudoff
    © 2004 | Addison-Wesley Professional | Cloth; 1024 pages | Instock
    ISBN-10: 0131411551 | ISBN-13: 9780131411555
    Brief Description | Buy from myPearsonStore

Pearson Higher Education offers special pricing when you choose to package your text with other student resources. If you're interested in creating a cost-saving package for your students contact your Pearson Higher Education representative.


Copyright ©2008 Pearson Education. All rights reserved. Legal Notice | Privacy Policy | Permissions