[Function Name]


[The function's declaration. Example]

Sort is an overloaded name; there are actually two sort functions.

template <class RandomAccessIterator>
void sort(RandomAccessIterator first, RandomAccessIterator last);

template <class RandomAccessIterator, class StrictWeakOrdering>
void sort(RandomAccessIterator first, RandomAccessIterator last, StrictWeakOrdering comp);


[A summary of what the function does. Example:]

Sort sorts the elements in [first, last) into ascending order, meaning that if i and j are any two valid iterators in [first, last) such that i precedes j, then *j is not less than *i.

The two versions of sort differ in how they define whether one element is less than another. The first version compares objects using operator<, and the second compares objects using a function object comp.

Type requirements

[This section lists the requirements that must be satisfied by the function's template parameters. If the function has no template parameters, this section can be skipped. Example:]

Models RandomAccessIterator concept
is mutable
value type is LessThanComparable.
is a model of StrictWeakOrdering.
is convertible to StrictWeakOrdering's argument type


[Functions usually aren't guaranteed to yield a well-defined result for any possible input, but only for valid input; it is an error to call a function with invalid input. This section describes the conditions for validity. Example:]

[first, last) is a valid range.



O(N log(N)) comparisons (both average and worst-case), where N is last - first. [2]


[A link to the source code where the function header is defined.]

#include <algorithm>

Example of use

[A code fragment that illustrates how to use the function.]

#include <algorithm>

int A[] = {1, 4, 2, 8, 5, 7};
const int N = sizeof(A) / sizeof(int);
sort(A, A + N);
copy(A, A + N, ostream_iterator<int>(cout, " "));
// The output is " 1 2 4 5 7 8"


Footnotes (if any) that are referred to by other parts of the page.

See Also

Links to other related pages.

There are 0 comments and replies

Comment on This Page