Sort a range of elements
This pattern is licensed under the CC0 Public Domain Dedication.
Sort elements in a range into a given order.
On line 10, we call the standard alrogithm
std::sort, which sorts the range of
elements between the given pair of iterators. We use
std::end to get the begin and end iterators
for the array.
operator< to sort the range, which
arranges the elements in ascending order. It can, however, be
passed a comparison function object to use when comparing
elements. On lines 12–13, we pass an object of type
std::greater<int>, which is a
comparison function object that uses
operator>. Accordingly, this
sorts the array in descending order.