没有合适的资源?快使用搜索试试~ 我知道了~
Effective STL pdf
5星 · 超过95%的资源 需积分: 10 7 下载量 198 浏览量
2014-02-18
10:16:29
上传
评论
收藏 1.82MB PDF 举报
温馨提示
试读
200页
Effective STL: 50 Specific Ways to Improve Your Use of the Standard Template Library
资源推荐
资源详情
资源评论
Effective STL
Author: Scott Meyers
E-version is made by:
Strangecat@epubcn
Thanks is given to j1foo@epubcn, who has helped to revise this e-book.
Content
Containers........................................................................................1
Item 1. Choose your containers with care........................................................... 1
Item 2. Beware the illusion of container-independent code................................ 4
Item 3. Make copying cheap and correct for objects in containers..................... 9
Item 4. Call empty instead of checking size() against zero. ............................. 11
Item 5. Prefer range member functions to their single-element counterparts... 12
Item 6. Be alert for C++'s most vexing parse................................................... 20
Item 7. When using containers of newed pointers, remember to delete the
pointers before the container is destroyed. ........................................................... 22
Item 8. Never create containers of auto_ptrs. ................................................... 27
Item 9. Choose carefully among erasing options.............................................. 29
Item 10. Be aware of allocator conventions and restrictions. ......................... 34
Item 11. Understand the legitimate uses of custom allocators........................ 40
Item 12. Have realistic expectations about the thread safety of STL containers.
43
vector and string............................................................................48
Item 13. Prefer vector and string to dynamically allocated arrays.................. 48
Item 14. Use reserve to avoid unnecessary reallocations................................ 50
Item 15. Be aware of variations in string implementations. ........................... 52
Item 16. Know how to pass vector and string data to legacy APIs. ............... 57
Item 17. Use "the swap trick" to trim excess capacity.................................... 60
Item 18. Avoid using vector<bool>. ............................................................... 62
Associative Containers..................................................................65
Item 19.
Understand the difference between equality and equivalence.......... 65
Item 20. Specify comparison types for associative containers of pointers. .... 69
Item 21. Always have comparison functions return false for equal values. ... 73
Item 22. Avoid in-place key modification in set and multiset. ....................... 76
Item 23. Consider replacing associative containers with sorted vectors. ....... 81
Item 24. Choose carefully between map::operator[] and map-insert when
efficiency is important. ......................................................................................... 87
Item 25. Familiarize yourself with the nonstandard hashed containers.......... 91
Iterators..........................................................................................96
Item 26. Prefer iterator to const iterator, reverse_iterator, and
const_reverse_iterator. .......................................................................................... 96
Item 27. Use distance and advance to convert a container's const_iterators to
iterators. 99
Item 28. Understand how to use a reverse_iterator's base iterator................ 102
Item 29. Consider istreambuf_iterators for character-by-character input..... 104
Algorithms ...................................................................................107
Item 30. Make sure destination ranges are big enough................................. 107
Item 31. Know your sorting options. ............................................................ 112
Item 32. Follow remove-like algorithms by erase if you really want to remove
something. 117
Item 33. Be wary of remove-like algorithms on containers of pointers. ...... 121
Item 34. Note which algorithms expect sorted ranges. ................................. 124
Item 35. Implement simple case-insensitive string comparisons via mismatch
or lexicographical compare................................................................................. 127
Item 36. Understand the proper implementation of copy_if......................... 131
Item 37. Use accumulate or for_each to summarize ranges. ........................ 133
Functors, Functor Classes, Functions, etc.................................139
Item 38.
Design functor classes for pass-by-value. ...................................... 139
Item 39. Make predicates pure functions. ..................................................... 142
Item 40. Make functor classes adaptable. ..................................................... 145
Item 41. Understand the reasons for ptr_fun, mem_fun, and mem_fun_ref. 149
Item 42. Make sure less<T> means operator<.............................................. 152
Programming with the STL .......................................................156
Item 43. Prefer algorithm calls to hand-written loops. ................................. 156
Item 44. Prefer member functions to algorithms with the same names........ 163
Item 45. Distinguish among count, find, binary search, lower_bound,
upper_bound, and equal_range. .......................................................................... 166
Item 46. Consider function objects instead of functions as algorithm
parameters. 174
Item 47. Avoid producing write-only code................................................... 178
Item 48. Always #include the proper headers............................................... 180
Item 49. Learn to decipher STL-related compiler diagnostics...................... 182
Item 50. Familiarize yourself with STL-related web sites............................ 188
剩余199页未读,继续阅读
资源评论
- leo_dddd2014-02-18正在搞c++开发,这个可以看看,很好!
- 有情剑客无情剑2014-03-03经典书籍,可是英文的。。。
HunterHung
- 粉丝: 0
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功