Standard Template Library Learning

Source: Internet
Author: User

Note:
1. When using the iterator, you prefer to use ++ POS instead of POS ++. The latter will generate a temporary object, which is out of efficiency considerations.
2. Auto_ptr is not needed as much as possible. Higher security means less flexibility.
3. Try to useAlgorithmReplace loops. When necessary, use custom predicates and function objects as much as possible. The overload operator () is critical.
4. Let's look at the six sorting algorithms. Sort, partion, nth_element .....
5. Remember the differences between vector, list, And deque, and select the most appropriate one.
6. Set is automatically sorted.
7. Binary predicates:
Copy (A. Begin (), A. End (), B. Begin ())
Requirement: the length of B is at least equal to a. The copy operation starts from the first element of Table A until the end of the first element of Table.
Input the element to B in sequence.
Likewise
Equal (A. Begin (), A. End (), B. Being ())
The meaning of this algorithm is to compare the elements in Table A with those in table B one by one. If table A is completely traversed, true is returned if it is equal,
This algorithm is actually a substring search algorithm.
8. To avoid errors, STL provides us with some adapters, which can be used directly to automatically allocate the required space.
Generally, STL provides three types of iterator adapter, back_insertor (table) and insertor (table)
9. Stream iterator Adapter. The syntax is maddening.
10 thus, remove () did not change the number of elements in the collection for which it was called.
When you call remove, you must note that when there are many elements, what is the value of the removed element?
11. Distance (iteraotrb, iteraotre );
Returns the distance between two pointers.
12. We prefer to use Member algorithms instead of general algorithms as much as possible, because universality usually results in a loss of efficiency.

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.