STL items

这篇书评可能有关键情节透露
重点:
item 1, 5, 9, 14, 18, 24, 28, 31
Item 5. Prefer range member functions to their single-element counterparts.
Item 9. eg: container.erase(remove(c.begin(), c.end(), target), c.end());
(1) To eliminate all objects in a container that have a particular value: If the container is a vector, string, or deque, use the erase-remove idiom. If the container is a list, use list::remove. 33 If the container is a standard associative container, use its erase member function.
(2) To eliminate all objects in a container that satisfy a particular predicate: If the container is a vector, string, or deque, use the erase-remove_if idiom. If the container is a list, use list::remove_if. If the container is a standard associative container, use remove_copy_if and swap, or write a loop to walk the container elements, being sure to postincrement your iterator when you pass it to erase.
(3) To do something inside the loop (in addition to erasing objects): If the container is a standard sequence container, write a loop to walk the container elements, being sure to update your iterator with erase's return value each time von call it. If the container is a standard associative container, write a loop to walk the container elements, being sure to postincrement your iterator when you pass it to erase. As you can see, there's more to erasing container elem
Item 14. Use reserve to avoid unnecessary reallocations.
Item18. std::vector<bool>做了内存上的优化,可以使用std::deque<bool>, std::bitset代替
Item 24. Choose carefully between map::operator[] and map-insert when efficiency is important.
Item28. Understand how to use a reverse_iterator's base iterator.
Item31.
(1) If you need to perform a full sort on a vector, string, deque, or array, you can use sort or stable_sort.
(2) If you have a vector, string, deque, or array and you need to put only the top n elements in order, partial_sort is available.
(3) If you have a vector, string, deque, or array and you need to identify the element at position n or you need to identify the top n elements without putting them in order. nth_element is at your beck and call.
(4) If you need to separate the elements of a standard sequence container or an array into those that do and do not satisfy some criterion, you're probably looking for partition or stable_partition.
(5) If your data is in a list, you can use partition and stable_partition directly, and you can use list-sort in place of sort and stable_sort. If you need the effects offered by partial_sort or nth_element, you'll have to approach the task indirectly, but there are a number of options, as I sketched above.