& Ldquo;This is Effective C++ volume three & ndash; it & rsquo;s really that good. & rdquo; & ndash; Herb Sutter, independent consultant and secretary of the ISO/ANSI C++ standards committee & ldquo;There are very few books which all C++ programmers must have. Add Effective STL to that list. & rdquo; & ndash; Thomas Becker, Senior Software Engineer, Zephyr Associates, Inc., and columnist, C/C++ Users Journal C++ & rsquo;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 & ndash; the things they almost always do or almost always avoid doing & ndash; to get the most out of the library. Other books describe what & rsquo;s in the STL. Effective STL shows you how to use it . Each of the book & rsquo;s 50 guidelines is backed by Meyers & rsquo; legendary analysis and incisive examples, so you & rsquo;ll learn not only what to do, but also when to do it & ndash; 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 & rsquo; 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 Обложка ......Page 1 Предисловие ......Page 9 Благодарности ......Page 11 Введение ......Page 15 STL и Стандарты ......Page 16 Подсчет ссылок ......Page 17 Терминология ......Page 18 Примеры ......Page 20 Рекомендации ......Page 22 Совет 1. Внимательно подходите к выбору контейнера ......Page 23 Совет 2. Остерегайтесь иллюзий контейнерно-независимого кода ......Page 27 Совет 3. Реализуйте быстрое и корректное копирование объектов в контейнерах ......Page 31 Совет 4. Вызывайте empty вместо сравнения size() с нулем ......Page 33 Совет 5. Используйте интервальные функции вместо одноэлементных ......Page 35 Совет 6. Остерегайтесь странностей лексического разбора С++ ......Page 42 Совет 7. При использовании контейнеров указателей, для которых вызывался оператор new, не забудьте вызвать delete для указателей перед уничтожением контейнера ......Page 44 Совет 8. Никогда не создавайте контейнеры, содержащие auto_ptr ......Page 48 Совет 9. Тщательно выбирайте операцию удаления ......Page 50 Совет 10. Помните о правилах и ограничениях распределителей памяти ......Page 54 Совет 11. Учитывайте область применения пользовательских распределителей памяти ......Page 60 Совет 12. Разумно оценивайте потоковую безопасность контейнеров STL ......Page 62 Совет 13. Используйте vector и string вместо динамических массивов ......Page 66 Совет 14. Используйте reserve для предотвращения лишних операций перераспределения памяти ......Page 68 Совет 15. Помните о различиях в реализации string ......Page 71 Совет 16. Научитесь передавать данные vector и string функциям унаследованного интерфейса ......Page 75 Совет 17. Используйте "фокус с перестановкой" для уменьшения емкости ......Page 78 Совет 18. Избегайте vector ......Page 80 Совет 19. Помните о различиях между равенством и эквивалентностью ......Page 83 Совет 20. Определите тип сравнения для ассоциативного контейнера, содержащего указатели ......Page 87 Совет 21. Следите за тем, чтобы функции сравнения возвращали false в случае равенства ......Page 91 Совет 22. Избегайте изменения ключа "на месте" в контейнерах set и multiset ......Page 93 Совет 23. Рассмотрите возможность замены ассоциативных контейнеров сортированными векторами ......Page 98 Совет 24. Тщательно выбирайте между map:: operator[ и map:: insert ......Page 103 Совет 25. Изучите нестандартные хэшированные контейнеры ......Page 107 Совет 26. Старайтесь использовать iterator вместо const_iterator, reverse_iterator и const_reverse_iterator ......Page 111 Совет 27. Используйте distance и advance для преобразования const_iterator в iterator ......Page 114 Совет 28. Научитесь использовать функцию base ......Page 117 Совет 29. Рассмотрите возможность использования istreambuf_iterator при посимвольном вводе ......Page 119 Глава 5 Алгоритмы ......Page 122 Совет 30. Следите за тем, чтобы приемный интервал имел достаточный размер ......Page 123 Совет 31. Помните о существовании разных средств сортировки ......Page 127 Совет 32. Сопровождайте вызовы remove-подобных алгоритмов вызовом erase ......Page 131 Совет 33. Будьте внимательны при использовании remove-подобных алгоритмов с контейнерами указателей ......Page 135 Совет 34. Помните о том, какие алгоритмы получают сортированные интервалы ......Page 138 Совет 35. Реализуйте простые сравнения строк без учета регистра символов с использованием mismatch или lexicographical_compare ......Page 141 Совет 36. Правильно реализуйте copy_if ......Page 144 Совет 37. Используйте accumulate или for_each для обобщения интервальных данных ......Page 146 Совет 38. Проектируйте классы функторов для передачи по значению ......Page 151 Совет 39. Реализуйте предикаты в виде "чистых" функций ......Page 154 Совет 40. Классы функторов должны быть адаптируемыми ......Page 157 Совет 41. Разберитесь, для чего нужны ptr_fun, mem_fun и mem_fun_ref ......Page 161 Совет 42. Следите за тем, чтобы конструкция less означала operator < ......Page 164 Совет 43. Используйте алгоритмы вместо циклов ......Page 167 Совет 44. Используйте функции контейнеров вместо одноименных алгоритмов ......Page 174 Совет 45. Различайте алгоритмы count, find, binary_search, lower_bound, upper_bound и equal_range ......Page 177 Совет 46. Передавайте алгоритмам объекты функций вместо функций ......Page 184 Совет 47. Избегайте "нечитаемого" кода ......Page 187 Совет 48. Всегда включайте нужные заголовки ......Page 190 Совет 49. Научитесь читать сообщения компилятора ......Page 191 Сайт SGI STL ......Page 198 Сайт STLport ......Page 200 Сайт Boost ......Page 201 Книги, написанные мной ......Page 203 Книги, написанные другими авторами ......Page 204 Ошибки и опечатки ......Page 206 Сравнение строк без учета регистра символов ......Page 207 Первая попытка ......Page 208 Локальный контекст ......Page 210 Локальные контексты в С++ ......Page 211 Сравнение строк без учета регистра ......Page 212 Шаблоны функций классов в STL ......Page 216 MSVC версий 4-6 ......Page 217 Обходное решение для MSVC 4-5 ......Page 218 Обходное решение для MSVC 6 ......Page 219 Алфавитный указатель ......Page 221 Обложка ......Page 226
“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.
booknews
explains How To Combine Stl Components To Take Advantage Of The Library's Design, Describes Common Stl Errors And How To Avoid Them, And Discusses Ways To Optimize Code. Guidelines Give Advice On Choosing Among Standard Stl Containers, Discuss Portability Problems, Explain The Proper Use Of Algorithms And Member Functions Whose Names Are The Same But Whose Actions Differ, And Gives Insight Into The Behavior Of Iterators, Function Objects, And Allocators. Appendices Discuss Locales And Case-insensitive String Comparisons, And Microsoft's Stl Platforms. For Stl Programmers. Meyers Has Written Several Books On C++. Annotation C. Book News, Inc., Portland, Or (booknews.com)
The goal of this book is to provide the working C++ programmer with fifty specific ways to improve his or her use of C++'s Standard Template Library. It gives advice on what should be done, and why, and what should not be done, and why not. It focuses on iterators, containers, function objects, and algorithms. It concentrates on using the STL, not extending it.