Still needs some work ...

Applying | Bounding | Comparing | Copying | Counting | Filling | Filtering | Generating | Heap Operations | Math Operations | Merging | Min/Max | Partitioning | Permuting | Randomizing/Shuffling | Removing | Replacing | Reversing | Rotating | Searching | Set Operations | Sorting | Swapping | Transforming

This page contains two tables. The first one gives an "algorithm interface key". The second gives a list of all STL algorithms grouped by purpose, and uses the algorithm interface key from the first table to keep the list as concise as possible. Each algorithm interface will (eventually) be a link to the more detailed description and any associated sample program(s) for that algorithm which appear in the (more complete) alphabetical algorithm listing.

Algorithm interface key for the algorithm catalog

This algorithm "interface key" shown in the first table below is an extended version of the one found in The STL <PRIMER>, and contains a few more symbols to help provide a little more information in the abbreviated forms of the algorithms shown here. Also, because the notation here is based on that source, it differs (though not confusingly so, one hopes) from the notation used on the other STL reference pages on this site.

Here are some notes on the table and its use with the algorithm "catalog" which follows:

  1. The notation (f,f) is a shorthand for an actual pair of the form pair<FowardIterator,ForwardIterator>.
  2. When a sequence of iterators like (...i1,i1,i2...) or (...f1,f1,f2,f2,...) appears in an algorithm parameter list, the different digits are used to indicate that there are two different iterators of the same iterator type at play in the same situation.
  3. Whenever two iterators designated by the same letter or letter-digit combination (as in (...i,i...) or (...f2,f2...)) follow one another, they should be interpreted as determining a range of values (in the usual STL sense of a range). When there are three such iterators in the sequence (as in (...i,i,i...) or (...f2,f2,f2...)), the first and last iterators should be interpreted as determining a range within which the middle iterator points to an intermediate, or "middle" value.
  4. Often there are two versions of an algorithm. The brief description is always for the first version. The second version is generally one that takes an additional (functional) parameter that modifies a test or behavior of the first version in what may be an obvious way, given the nature of the algorithm. For more details in any particular case, follow the link and consult the description of the longer version of the algorithm.
Algorithm Interface Key
Iterators
Key Meaning
b a bidirectional iterator
f a forward iterator
i an input iterator
o an output iterator
r a random access iterator
(?, ?) a pair of iterators as a return value, as in (f,f)
Predicates and other functions
Key Meaning
upred a unary predicate (boolean function or function object)
(generally used to test a single value from a container)
bpred a binary predicate (boolean function or function object)
(generally used to compare the order of two values from a container)
ufunc a unary (value-returning) function (or function object)
bfunc a binary (value-returning) function (or function object)
pfunc a "parameterless" (value-returning) function (or function object)
(often used to "generate" a value of some kind)
uproc a unary procedure (void function or function object)
bproc a binary procedure (void function or function object)
pproc a "parameterless" procedure (void function or function object)
Other items
key meaning
n a quantity (or size)
v a value
& a (generally const) reference to a value

Algorithm catalog with algorithms grouped by purpose

One or more algorithms may conceptually fit into more than one grouping. For example, the includes algorithm could be placed either where it is (in the Set Operations group), or in the Searching group of algorithms. However, to avoid any potential confusion caused by such duplication, each algorithm appears only once, in what we hope is its most appropriate location. Every use of the term "function" can be read as "function or function object", and every use of the phrase "end of a/the range" can be interpreted as "one-past-the-last position of the range".

Catalog of Algorithms Grouped by Purpose
Applying
ufunc for_each(i,i,ufunc)
Apply a function to every item in a range and return the function.
Bounding
(f,f) equal_range(f,f,&)
(f,f) equal_range(f,f,&,bpred)

Find the lower bound and upper bound of a value within a range and return a pair of iterators pointing to those two values (in that order).
f lower_bound(f,f,&)
f lower_bound(f,f,&,bpred)

Find the lower bound of a value within a range and return an iterator pointing to it.
f upper_bound(f,f,&)
f upper_bound(f,f,&,bpred)

Find the upper bound of a value within a range and return an iterator pointing to it.
Comparing
bool equal(i1,i1,i2)
bool equal(i1,i1,i2,bpred)

Check if the values in two ranges match.
bool lexicographical_compare(i1,i1,i2,i2)
bool lexicographical_compare(i1,i1,i2,i2,bpred)

Compare two ranges lexicographically, and return true if the first range is less than the second; otherwise return false.
(i1,i2) mismatch(i1,i1,i2)
(i1,i2) mismatch(i1,i1,i2, bpred)

Search two ranges for the first two items in corresponding positions that don't match, and return a pair of iterators pointing to those two items.
Copying
o copy(i,i,o)
Copy a range of items to a destination and return an iterator pointing to the end of the copied range.
b2 copy_backward(b1,b1,b2)
Copy a range of items backwards to a destination and return an iterator pointing to the end of the copied range.
Counting
n count(i,i,&)
Count the items in a range that match a value and return that count.
n count_if(i,i,upred)
Count the items in a range that satisfy a predicate and return that count.
Filling
fill(f,f,&)
Set every item in a range to a particular value.
fill_n(o,n,&)
Set n items to a particular value.
Filtering
f unique(f,f)
f unique(f,f,bpred)

Collapse each group of consecutive duplicate values in a range of values to a single value, and return an iterator pointing to the end of the modified range. .
o unique_copy(i,i,o)
o unique_copy(i,i,o,bpred)

Copy a range of values, performing the same action as unique above, and return an iterator pointing to the end of the new range. .
Generating
generate(f,f,pfunc)
Fill a range with generated values.
generate_n(o,n,pfunc)
Generate a specified number of values.
Heap Operations
make_heap(r,r)
make_heap(r,r,bpred)

Make a range of values into a heap.
pop_heap(r,r)
pop_heap(r,r,bpred)

Delete the first value from a heap.
push_heap(r,r)
push_heap(r,r,bpred)

Insert the last value of a range into a heap.
sort_heap(r,r)
sort_heap(r,r,bpred)

Sort a heap.
Math Operations (from <numeric>)
v accumulate(i,i,v)
v accumulate(i,i,v,bfunc)

Sum an initial value and the values in a range, and return the sum.
o adjacent_difference(i,i,o)
o adjacent_difference(i,i,o,bfunc)

Calculate the difference between adjacent pairs of values, write the differences to an output range, and return an iterator pointing to the end of that output range.
v inner_product(i1,11,i2,vInitial)
v inner_product(i1,i1,i2,v,bfunc1,bfunc2)

Calculate the inner product of two ranges and return that value plus vInitial.
o partial_sum(i,i,o)
o partial_sum(i,i,o, bfunc)

Fill a range with running totals and return an iterator pointing to ... .
Merging
inplace_merge(b,b,b)
inplace_merge(b,b,b,bpred)

Merge two sorted ranges, in place, into a single sorted range.
o merge(i1,i1,i2,i2,o)
o merge(i1,i1,i2,i2,o,bpred)

Merge two sorted ranges into a single sorted range.
Min/Max
& min(&,&)
& min(&,&,bpred)

Find the minimum of two values and return a reference to that value.
& max(&,&)
& max(&,&,bpred)

Find the maximum of two values and return a reference to that value.
f min_element(f,f)
f min_element(f,f,bpred)

Find the minimum value in a range and return an iterator pointing to that value.
f max_element(f,f)
f max_element(f,f,bpred)

Find the maximum value in a range and return an iterator pointing to that value.
Partitioning
nth_element(r,r,r)
nth_element(r,r,r,bpred)

Partition a range of values so that the value pointed to by the middle r in the parameter list is in its correct sorted position, and no element to its left is greater than any element to its right.
b partition(b,b,upred)
Partition a range of values using a predicate, and return an iterator pointing to the first value for which upred returns false.
b stable_partition(b,b,upred)
Partition a range using a predicate without altering the relative order of the values, and return an iterator pointing to the first value for which upred returns false.
Permuting
bool next_permutation(b,b)
bool next_permutation(b,b,bpred)

Change a range of values to the next lexicographic permutation of those values, and return true, or return false if no next permuation exists.
bool prev_permutation(b,b)
bool prev_permutation(b,b,bpred)

Change a range of values to the previous lexicographic permutation of those values, and return true, or return false if no previous permuation exists.
Randomizing/Shuffling
random_shuffle(r,r)
random_shuffle(r,r,ranGen)

Randomize a range of values, and use the random generator function ranGen, if supplied, rather than an internal random generator.
Removing
remove(f,f,&)
Remove from a range of values all values that match a give value.
remove_if(f,f,upred)
Remove values that satisfy a predicate from a range of values.
remove_copy(i,i,o,&)
Copy a range of values, removing all values that match a given value.
remove_copy_if(i,i,o,upred)
Copy a range of values, removing all values that satisfy a predicate.
Replacing
replace(f,f,&,&)
Replace, within a range of values, one specified value with another value.
replace_if(f,f,upred,&)
Replace, within a range of values, each value that satisfies a predicate with a specified value.
replace_copy(i,i,o,&,&)
Copy a range of values, replacing one specified value with another specified value.
replace_copy_if(i,i,o,upred,&)
Copy a range of values, replacing each value that satisfies a predicate with a specified value.
Reversing
reverse(b,b)
Reverse the order of all values in a range of values.
reverse_copy(b,b,o)
Write to an output destination a reversed copy of a range of values.
Rotating
rotate(f,f,f)
Rotate a range of values by n positions.
rotate_copy(f,f,f,o)
Copy a range of values to an output destination, rotating it by n position.
Searching
f adjacent_find(f,f)
f adjacent_find(f,f, bpred)

Search for the first pair of equal adjacent values in a range of values, and return an iterator pointing to the first value of the pair.
bool binary_search(f,f,&)
Search for a value in a sorted range of values and return true if found, false if not found.
i find(i,i,&)
Search for a value in a range of values, and return an iterator pointing to the value or to the end of the range if the value was not found.
f1 find_end(f1,f1,f2,f2)
f1 find_end(f1,f1,f2,f2,bpred)

Search for the last occurrence of a second range of values in a first range of values and return an iterator pointing to the first value of that last match within the first range, or pointing to the end of the first range if the second range of values does not occur within the first range of values.
f1 find_first_of(f1,f1,f2,f2)
f1 find_first_of(f1,f1,f2,f2,bpred)

Search for any of the values from a second range in a first range and return an iterator pointing to the first such value found, or to the end of the first range if no such value was found.
i find_if(i,i,upred)
Search for a value that satisfies a predicate and return an iterator pointing to the first such value, or to the end of the range if there is no such value.
f1 search(f1,f1,f2,f2)
f1 search(f1,f1,f2,f2)

Search for the first occurrence of a second range of values within a first range of values and return an iterator pointing to the first value of that first match within the first range, or pointing to the end of the first range if the second range of values does not occur within the first range of values.
f search_n(f,f,n,&)
f search_n(f,f,n,&,bpred)

Search in a range of values for a contiguous sequence of n values each equal to &, and return an iterator pointing to the first of those values, or to the end of the range if the search is unsuccessful.
Set Operations
bool includes(i1,i1,i2,i2)
bool includes(i1,i1,i2,i2,bpred)

Search for all values from the second range in the first range and return true if found, otherwise return false.
o set_difference(i1,i1,i2,i2,o)
o set_difference(i1,i1,i2,i2,o,bpred)

Create an output range of values that are in the first range but not in the second range and return an iterator pointing to the end of that output range.
o set_intersection(i1,i1,i2,i2,o)
o set_intersection(i1,i1,i2,i2,o,bpred)

Create an output range of values that are in the first range and also in the second range and return an iterator pointing to the end of that output range.
o set_symmetric_difference(i1,i1,i2,i2,o)
o set_symmetric_difference(i1,i1,i2,i2,o,bpred)

Create an output range of values that are not common to both ranges and return an iterator pointing to the end of that output range.
o set_union(i1,i1,i2,i2,o)
o set_union(i1,i1,i2,i2,o,bpred)

Create an output range of values that are either in the first range or in the second range and return an iterator pointing to the end of that output range.
Sorting
partial_sort(r,r,r)
partial_sort(r,r,r,bpred)

Sort all values till first part of range is in sorted order.
r partial_sort_copy(i,i,r,r)
r partial_sort_copy(i,i,r,r,bpred)

Partially sort a range of values (as above) and copy as many values as will fit into an output range.
sort(r,r)
sort(r,r,bpred)

Sort a range of values.
stable_sort(r,r)
stable_sort(r,r,bpred)

Sort a range of values, maintaining the same relative order of duplicate values.
Swapping
iter_swap(f,f)
Swap the values pointed to by the two iterators.
swap(&,&)
Swap the two values.
f2 swap_ranges(f1,f1,f2)
Swap the corresponding values in two ranges of values and return an iterator pointing to the end of the second range.
Transforming
o transform(i,i,o,ufunc)
o transform(i,i,o,bfunc)

Transform one range of values into another.