Summarize the basic forms of general STL Algorithms

Source: Internet
Author: User

The general algorithm of STL has the following four forms:

  1. ALG (beg, end, Params): uses the source input as the output.
  2. ALG (beg, end, DEST, Params): Use DEST as the output and ensure sufficient space. Therefore, inserter is often used.
  3. ALG (beg, end, beg2, other Params): beg2 is used as the output. It is assumed that the range starting with beg2 is at least as large as that specified by beg and end.
  4. ALG (beg, end, beg2, end2, Params): beg2 end2 as the output

Example:

The first type is as follows:

Find (beg, end, search_value); sort (beg, end); accumulate (beg, end, original_value); fill (beg, end, value); // special: fill_n (begin, Count, n) Replace (beg, end, value, replace_value); unique (beg, end); count (beg, end, value); stable_sort (beg, end); reverse (beg, end );

The second type is as follows:

copy(beg, end, back_inserter(vector));

The third type is as follows:

replace_copy(beg, end, beg2, value, replace_value);unique_copy(beg, end, beg2);reverse_copy(beg, end, beg2);

The fourth type is:

find_first_of(beg, end, beg2, end2);

In addition, some algorithms support predicates, such

sort(beg, end, comp)find_if(beg, end, comp)count_if(beg, end, comp)

Some algorithms include copy and non-copy versions, such

replace(beg, end, value, replace_value);unique(beg, end);replace_copy(beg, end, beg2, value, replace_value);unique_copy(beg, end, beg2);    

This article is copyrighted by cxh_me. It is difficult to create an original document. If you do not copy this article, please indicate the source for the reprinting. Thank you.

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.