Effective STL: 50 Specific Ways to Improve Your Use of the Standard Template Library (Paperback)

Scott Meyers

  • 出版商: Addison Wesley
  • 出版日期: 2001-06-06
  • 售價: $2,150
  • 貴賓價: 9.5$2,043
  • 語言: 英文
  • 頁數: 288
  • 裝訂: Paperback
  • ISBN: 0201749629
  • ISBN-13: 9780201749625
  • 相關分類: C++ 程式語言
  • 已絕版

買這商品的人也買了...

相關主題

商品描述

 

Description

 

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.

Back to Top


Appropriate Courses



Back to Top

 

Features

  •  

Back to Top

 

Table Of Contents

 

Preface.
Acknowledgments.
Introduction.
1. Containers.

 

Item 1: Choose your containers with care.
Item 2: Beware the illusion of container-independent code.
Item 3: Make copying cheap and correct for objects in containers.
Item 4: Call empty instead of checking size against zero.
Item 5: Prefer range member functions to their single-element counterparts.
Item 6: Be alert for C++'s most vexing parse.
Item 7: When using containers of newed pointers, remember to delete the pointers before the container is destroyed.
Item 8: Never create containers of auto_ptrs.
Item 9: Choose carefully among erasing options.
Item 10: Be aware of allocator conventions and restrictions.
Item 11: Understand the legitimate uses of custom allocators.
Item 12: Have realistic expectations about the thread safety of STL containers.


2. Vector and string.

 

Item 13: Prefer vector and string to dynamically allocated arrays.
Item 14: Use reserve to avoid unnecessary reallocations.
Item 15: Be aware of variations in string implementations.
Item 16: Know how to pass vector and string data to legacy APIs.
Item 17: Use "the swap trick" to trim excess capacity.
Item 18: Avoid using vector.


3. Associative Containers.

 

 

Item 19: Understand the difference between equality and equivalence.
Item 20: Specify comparison types for associative containers of pointers.
Item 21: Always have comparison functions return false for equal values.
Item 22: Avoid in-place key modification in set and multiset.
Item 23: Consider replacing associative containers with sorted vectors.
Item 24: Prefer map::insert to map::operator when efficiency is a concern.
Item 25: Familiarize yourself with the nonstandard hashed containers.


4. Iterators.

 

 

Item 26: Prefer iterator to const_iterator, reverse_iterator, and const_reverse_iterator.
Item 27: Use distance and advance to convert const_iterators to iterators.
Item 28: Understand how to use a reverse_iterator's base iterator.
Item 29: Consider istreambuf_iterators for character by character input.


5. Algorithms.

 

 

Item 30: Make sure destination ranges are big enough.
Item 31: Know your sorting options.
Item 32: Follow remove-like algorithms by erase if you really want to remove something.
Item 33: Be wary of remove-like algorithms on containers of pointers.
Item 34: Note which algorithms expect sorted ranges.
Item 35: Implement simple case-insensitive string comparisons via mismatch or lexicographical_compare.
Item 36: Use not1 and remove_copy_if to perform a copy_if.
Item 37: Use accumulate or for_each to summarize sequences.


6. Functors, Functor Classes, Functions, etc.

 

 

Item 38: Design functor classes for pass-by-value.
Item 39: Make predicates pure functions.
Item 40: Make functor classes adaptable.
Item 41: Understand the reasons for ptr_fun, mem_fun, and mem_fun_ref.
Item 42: Make sure less means operator<.


7. Programming with the STL.

 

 

Item 43: Prefer algorithm calls to hand-written loops.
Item 44: Prefer member functions to algorithms with the same names.
Item 45: Distinguish among count, find, binary_search, lower_bound, upper_bound, and equal_range.
Item 46: Consider function objects instead of functions as algorithm parameters.
Item 47: Avoid producing write-only code.
Item 48: Always #include the proper headers.
Item 49: Learn to decipher STL-related compiler diagnostics.
Item 50: Familiarize yourself with STL-related web sites.


Bibliography.
Appendix A. Locales and Case-Insensitive String Comparisons.
Appendix B. Remarks on Microsoft's STL Platforms.
Index.


Back to Top

 

 

商品描述(中文翻譯)

描述

C++的標準模板庫(STL)是一個革命性的工具,但學習如何有效使用它一直是學生們面臨的挑戰。在《Effective STL》中,暢銷作家Scott Meyers(《Effective C++》、《More Effective C++》)揭示了專家們所使用的關鍵經驗法則,即他們幾乎總是這樣做或幾乎總是避免做的事情,以充分利用這個庫。本書為C++程序員提供清晰、簡潔和具體的指南。其他書籍描述了STL的內容,而《Effective STL》則向讀者展示如何使用它。書中的每一條指南都由Meyers的傳奇分析和深入的例子支持,因此讀者不僅會學到該做什麼,還會學到何時以及為什麼要這樣做。

適合的課程

特點

目錄

前言。
致謝。
介紹。
1. 容器。

項目1:謹慎選擇容器。
項目2:小心容器獨立代碼的錯覺。
項目3:對於容器中的對象,使複製變得便宜且正確。
項目4:調用empty而不是檢查大小是否為零。
項目5:優先使用範圍成員函數而不是單個元素的對應函數。
項目6:警惕C++最令人困惑的解析。
項目7:在使用newed指針的容器時,記得在容器被銷毀之前刪除指針。
項目8:永遠不要創建auto_ptrs的容器。
項目9:在刪除選項之間仔細選擇。
項目10:了解分配器的約定和限制。
項目11:了解自定義分配器的合法用途。
項目12:對STL容器的線程安全性有現實的期望。

2. 向量和字符串。

項目13:優先使用向量和字符串而不是動態分配的數組。
項目14:使用reserve避免不必要的重新分配。
項目15:了解字符串實現的變化。
項目16:知道如何將向量和字符串數據傳遞給舊有API。
項目17:使用“交換技巧”來修剪多餘的容量。
項目18:避免使用vector。

3. 關聯容器。