IRIX 6.5 » Books » Developer »
Standard Template Library Programmer's Guide
(document number: 007-3426-004 / published: 1999-05-21)
table of contents | additional info | download
find in page
| Category: algorithms | Component type: function |
template <class ForwardIterator>
bool is_sorted(ForwardIterator first, ForwardIterator last)
template <class ForwardIterator, class StrictWeakOrdering>
bool is_sorted(ForwardIterator first, ForwardIterator last,
StrictWeakOrdering comp)
The two versions of is_sorted 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 the function object comp. The first version of is_sorted returns true if and only if, for every iterator i in the range [first, last - 1), *(i + 1) < *i is false. The second version returns true if and only if, for every iterator i in the range [first, last - 1), comp(*(i + 1), *i) is false
int A[] = {1, 4, 2, 8, 5, 7};
const int N = sizeof(A) / sizeof(int);
assert(!is_sorted(A, A + N));
sort(A, A + N);
assert(is_sorted(A, A + N));
Standard Template Library Programmer's Guide
(document number: 007-3426-004 / published: 1999-05-21)
table of contents | additional info | download
Copyright © 1993-2007 SGI, Inc. All rights reserved.