【摘抄】A Conclusion Of Choosing Among Erasing Options

2007-8-29 Nie.Meining Coding

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 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.

阅读全文>>

评论(0) 浏览(2165)

Powered by emlog