"To avoid resource leaks when you have containers of pointers that should be deleted, you must either replace the pointers with smart reference-counting pointer objects (such as Boost's shared_ptr) or you must manually delete each pointer in the container before the container is destroyed."
"1.the erase-remove idiom is the best way to get rid of elements with a specific value when c is a vector, string, or deque."
"2.the remove member function is the best way to get rid of elements with a specific value when c is a list."
"*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. If the container is a standard associative container, use its erase member function. *To eliminate all obje"
"The expression vector<Contestant>(contestants) creates a temporary vector that is a copy of contestants: vector's copy constructor does the work. However, vector's copy constructor allocates only as much memory as is needed for the elements being copied, so this temporary vector has no excess capaci"
"That's why it makes sense to consider using a sorted vector instead of an associative container only when you know that your data structure is used in such a way that lookups are almost never mixed with insertions and erasures."
"If you're updating an existing map element, operator[] is preferable, but if you're adding a new element, insert has the edge."
用户评论
心血来潮mark下老早前读过的书
scott meyers “effective三部曲”之三
教人如何正确使用stl库的经验之谈,还不错的~~
一身冷汗,我是用了多少野路子的STL用法。后面某些 functor 在 c++ 11/14/17 里已经 deprecated ,需要找本新的书看了。当然,我们线上还是老旧的 gcc