The general algorithm of STL has the following four forms:
- ALG (beg, end, Params): uses the source input as the output.
- ALG (beg, end, DEST, Params): Use DEST as the output and ensure sufficient space. Therefore, inserter is often used.
- 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.
- 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.