Effect STL Items

Item 1. Choose your containers with care.

Item 2. Beware the illusion of container-independent code.

Item 3. Make copying cheap and correct for objects in containers.

Item 4. Call empty instead of checking size() against zero.

Item 5. Prefer range member functions to their single-element counterparts.

Item 6. Be alert for C++'s most vexing parse.

Item 7. When using containers of newed pointers, remember to delete the pointers before the container is destroyed.

Item 8. Never create containers of auto_ptrs.

Item 9. Choose carefully among erasing options.

Item 10. Be aware of allocator conventions and restrictions.

Item 11. Understand the legitimate uses of custom allocators.

Item 12. Have realistic expectations about the thread safety of STL containers.

Item 13. Prefer vector and string to dynamically allocated arrays.

Item 14. Use reserve to avoid unnecessary reallocations.

Item 15. Be aware of variations in string implementations.

Item 16. Know how to pass vector and string data to legacy APIs.

Item 17. Use "the swap trick" to trim excess capacity.

Item 18. Avoid using vector<bool>.

Item 19. Understand the difference between equality and equivalence.

Item 20. Specify comparison types for associative containers of pointers.

Item 21. Always have comparison functions return false for equal values. 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章