Effective STL: 50 Specific Ways to Improve Your Use of the Standard Template Library (Paperback)
暫譯: 有效的 STL:50 種具體方法提升你對標準模板庫的使用

Scott Meyers

  • 出版商: Addison Wesley
  • 出版日期: 2001-06-06
  • 售價: $2,200
  • 貴賓價: 9.5$2,090
  • 語言: 英文
  • 頁數: 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++ 的標準模板庫(Standard Template Library, STL)是革命性的,但學會如何有效使用它對學生來說一直是一個挑戰。在《Effective STL》中,暢銷書作者 Scott Meyers(《Effective C++》、《More Effective C++》)揭示了專家們所使用的關鍵經驗法則——他們幾乎總是會做或幾乎總是會避免做的事情——以充分利用這個庫。本書為 C++ 程式設計師提供了清晰、簡潔且具體的指導。雖然其他書籍描述了 STL 中的內容,《Effective STL》則向學生展示了如何使用它。本書的 50 條指導原則都得到了 Meyers 傳奇般的分析和深刻的範例支持,因此學生不僅會學到該做什麼,還會了解何時該做以及為什麼要這樣做。

適合的課程

特點

目錄

前言。
致謝。
導言。
1. 容器。

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

2. 向量和字串。

項目 13:優先使用 vector 和 string 而非動態分配的數組。
項目 14:使用 reserve 以避免不必要的重新分配。
項目 15:注意字串實現的變化。
項目 16:知道如何將 vector 和 string 數據傳遞給舊版 API。
項目 17:使用「交換技巧」來修剪多餘的容量。
項目 18:避免使用 vector。

3. 關聯容器。

項目 19:理解相等和等價之間的區別。
項目 20:為指標的關聯容器指定比較類型。
項目 21:比較函數對於相等值應始終返回 false。
項目 22:避免在 set 和 multiset 中就地修改鍵。
項目 23:考慮用排序的向量替代關聯容器。
項目 24:在效率成為考量時,優先使用 map::insert 而非 map::operator。
項目 25:熟悉非標準的哈希容器。

4. 迭代器。

項目 26:優先使用 iterator 而非 const_iterator、reverse_iterator 和 const_reverse_iterator。
項目 27:使用 distance 和 advance 將 const_iterators 轉換為 iterators。
項目 28:理解如何使用 reverse_iterator 的基礎迭代器。
項目 29:考慮使用 istreambuf_iterators 進行逐字符輸入。

5. 算法。

項目 30:確保目標範圍足夠大。
項目 31:了解你的排序選項。
項目 32:如果真的想刪除某些東西,請遵循 remove 類算法後接 erase。
項目 33:對指標容器上的 remove 類算法保持警惕。
項目 34:注意哪些算法期望排序範圍。
項目 35:通過 mismatch 或 lexicographical_compare 實現簡單的大小寫不敏感字串比較。
項目 36:使用 not1 和 remove_copy_if 來執行 copy_if。
項目 37:使用 accumulate 或 for_each 來總結序列。

6. 函數對象、函數對象類、函數等。

項目 38:為按值傳遞設計函數對象類。
項目 39:使謂詞成為純函數。
項目 40:使函數對象類可適應。
項目 41:理解 ptr_fun、mem_fun 和 mem_fun_ref 的原因。
項目 42:確保 less 意味著 operator<。

7. 使用 STL 進行編程。

項目 43:優先使用算法調用而非手寫循環。
項目 44:優先使用成員函數而非同名算法。
項目 45:區分 count、find、binary_search、lower_bound、upper_bound 和 equal_range。
項目 46:考慮使用函數對象而非函數作為算法參數。
項目 47:避免產生只寫代碼。
項目 48:始終 #include 正確的標頭。
項目 49:學會解讀與 STL 相關的編譯器診斷信息。
項目 50:熟悉與 STL 相關的網站。

參考文獻。
附錄 A. 地區和大小寫不敏感的字串比較。
附錄 B. 關於 Microsoft 的 STL 平台的說明。
索引。