00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef STXXL_IS_SORTED_HEADER
00015 #define STXXL_IS_SORTED_HEADER
00016
00017 #include <stxxl/bits/namespace.h>
00018
00019
00020 __STXXL_BEGIN_NAMESPACE
00021
00022 template <class _ForwardIter>
00023 bool is_sorted_helper(_ForwardIter __first, _ForwardIter __last)
00024 {
00025 if (__first == __last)
00026 return true;
00027
00028 _ForwardIter __next = __first;
00029 for (++__next; __next != __last; __first = __next, ++__next) {
00030 if (*__next < *__first)
00031 return false;
00032 }
00033
00034 return true;
00035 }
00036
00037 template <class _ForwardIter, class _StrictWeakOrdering>
00038 bool is_sorted_helper(_ForwardIter __first, _ForwardIter __last,
00039 _StrictWeakOrdering __comp)
00040 {
00041 if (__first == __last)
00042 return true;
00043
00044 _ForwardIter __next = __first;
00045 for (++__next; __next != __last; __first = __next, ++__next) {
00046 if (__comp(*__next, *__first))
00047 return false;
00048 }
00049
00050 return true;
00051 }
00052
00053 template <class _ForwardIter>
00054 bool is_sorted(_ForwardIter __first, _ForwardIter __last)
00055 {
00056 return is_sorted_helper(__first, __last);
00057 }
00058
00059 template <class _ForwardIter, class _StrictWeakOrdering>
00060 bool is_sorted(_ForwardIter __first, _ForwardIter __last,
00061 _StrictWeakOrdering __comp)
00062 {
00063 return is_sorted_helper(__first, __last, __comp);
00064 }
00065
00066 __STXXL_END_NAMESPACE
00067
00068 #endif // !STXXL_IS_SORTED_HEADER