[Translation] Objective C ++, 3rd edition, appendix A. Beyond Objective C ++

Source: Internet
Author: User

Appendix A. BeyondValid C ++

By Scott Meyers

Translator: fatalerror99 (itepub's nirvana)

Release: http://blog.csdn.net/fatalerror99/

Valid C ++Covers the general guidelines that I think are most important to the current C ++ programmers, but if you are interested in improving your effectiveness in more aspects, I recommend that you study other C ++ books,More effective tive C ++AndValid STL.

More effective tive C ++Covers other programming guidelines and extensive discussions on topics such as efficiency and exceptional programming. It also describes important C ++ programming technologies such as smart pointers, reference counting, and proxy objects.

Valid STLImageValid C ++It is also a guideline-oriented book, but it focuses on the effective use of the standard template library.

The following is a summary of the two books.

ContentsMore effective tive C ++

Basics
Item 1: distinguish between pointers and references
Item 2: prefer C ++-style casts
Item 3: never treat arrays polymorphically
Item 4: avoid gratuitous Default constructors

Operators
Item 5: Be wary of user-defined conversion functions
Item 6: distinguish between prefix and Postfix forms of increment and Decrement Operators
Item 7: Never overload &, |, or,
Item 8: understand the different meanings of new and delete

Exceptions
Item 9: Use Destructors to prevent resource leaks
Item 10: prevent resource leaks in Constructors
Item 11: prevent exceptions from leaving Destructors
Item 12: Understand how throwing an exception differs from passing a parameter or calling a virtual function
Item 13: catch exceptions by reference
Item 14: use exception specifications judiciously
Item 15: understand the costs of Exception Handling

Efficiency
Item 16: Remember the 80-20 rule
Item 17: Consider using lazy Evaluation
Item 18: amortize the cost of expected computations
Item 19: understand the origin of temporary objects
Item 20: facilitate the return value Optimization
Item 21: overload to avoid implicit type conversions
Item 22: Consider usingOP =Instead of stand-aloneOP
Item 23: consider alternative Libraries
Item 24: understand the costs of virtual functions, multiple inheritance, virtual base classes, and rtti

Techniques
Item 25: virtualizing constructors and non-member functions
Item 26: limiting the number of objects of a class
Item 27: requiring or prohibiting heap-based Objects
Item 28: Smart pointers
Item 29: reference counting
Item 30: proxy classes
Item 31: Making functions virtual with respect to more than one object

Miscellany
Item 32: Program in the future tense
Item 33: make non-leaf classes Abstract
Item 34: understand how to combine C ++ and C in the same program
Item 35: familiarize yourself with the language standard

ContentsValid STL

Chapter 1: Containers
Item 1: Choose your containers with care.
Item 2: Beware the declaration 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.

Chapter 2: vector and string
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>.

Chapter 3: Associative containers
Item 19: understand the difference between ity and equivalence.
Item 20: Specify comparison types for Associative containers of pointers.
Item 21: Always Have comparison functions return false for equal values.
Item 22: Avoid in-place Key Modification in set and Multiset.
Item 23: consider replacing Associative containers with sorted vectors.
Item 24: Choose carefully between map: operator [] and map: insert when efficiency is important.
Item 25: familiarize yourself with the nonstandard hashed containers.

Chapter 4: iterators
Item 26: prefer iterator to const_iterator, reverse_iterator, and const_reverse_iterator.
Item 27: use distance and advance to convert a container's const_iterators to iterators.
Item 28: understand how to use a reverse_iterator's base iterator.
Item 29: Consider istreambuf_iterators for character-by-character input.

Chapter 5: Algorithms
Item 30: Make sure destination ranges are big enough.
Item 31: Know Your sorting options.
Item 32: Follow remove-like algorithms by erase if you really want to remove something.
Item 33: Be wary of remove-like algorithms on containers of pointers.
Item 34: Note which algorithms until CT sorted ranges.
Item 35: implement simple case-insensitive string comparisons via mismatch or lexicographical_compare.
Item 36: Understand the proper implementation of copy_if.
Item 37: Use accumulate or for_each to summarize ranges.

Chapter 6: functors, functor classes, functions, etc.
Item 38: Design functor classes for pass-by-value.
Item 39: Make predicates pure functions.
Item 40: Make functor classes adaptable.
Item 41: understand the reasons for ptr_fun, mem_fun, and mem_fun_ref.
Item 42: Make sure less <t> means operator <.

Chapter 7: programming with the STL
Item 43: prefer algorithm callto hand-written loops.
Item 44: prefer member functions to algorithms with the same names.
Item 45: distinguish among count, find, binary_search, lower_bound, upper_bound, and interval _range.
Item 46: Consider function objects instead of functions as algorithm parameters.
Item 47: avoid producing write-only code.
Item 48: always # include the proper headers.
Item 49: Learn to decipher STL-related compiler diagnostics.
Item 50: familiarize yourself with STL-related web sites.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.