Stxxl
1.4.0
|
00001 /*************************************************************************** 00002 * include/stxxl/bits/common/is_sorted.h 00003 * 00004 * Part of the STXXL. See http://stxxl.sourceforge.net 00005 * 00006 * Copyright (C) 2002 Roman Dementiev <dementiev@mpi-sb.mpg.de> 00007 * Copyright (C) 2008 Andreas Beckmann <beckmann@cs.uni-frankfurt.de> 00008 * 00009 * Distributed under the Boost Software License, Version 1.0. 00010 * (See accompanying file LICENSE_1_0.txt or copy at 00011 * http://www.boost.org/LICENSE_1_0.txt) 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