STXXL  1.4-dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
is_sorted.h
Go to the documentation of this file.
1 /***************************************************************************
2  * include/stxxl/bits/common/is_sorted.h
3  *
4  * Part of the STXXL. See http://stxxl.sourceforge.net
5  *
6  * Copyright (C) 2002 Roman Dementiev <[email protected]>
7  * Copyright (C) 2008 Andreas Beckmann <[email protected]>
8  *
9  * Distributed under the Boost Software License, Version 1.0.
10  * (See accompanying file LICENSE_1_0.txt or copy at
11  * http://www.boost.org/LICENSE_1_0.txt)
12  **************************************************************************/
13 
14 #ifndef STXXL_COMMON_IS_SORTED_HEADER
15 #define STXXL_COMMON_IS_SORTED_HEADER
16 
17 #include <stxxl/bits/namespace.h>
18 #include <iterator>
19 #include <functional>
20 
22 
23 template <class ForwardIterator, class StrictWeakOrdering>
24 bool is_sorted(ForwardIterator first, ForwardIterator last,
25  StrictWeakOrdering comp)
26 {
27  if (first == last)
28  return true;
29 
30  ForwardIterator next = first;
31  for (++next; next != last; ++first, ++next) {
32  if (comp(*next, *first))
33  return false;
34  }
35 
36  return true;
37 }
38 
39 template <class ForwardIterator>
40 bool is_sorted(ForwardIterator first, ForwardIterator last)
41 {
42  return stxxl::is_sorted(
43  first, last,
44  std::less<typename std::iterator_traits<ForwardIterator>
45  ::value_type>());
46 }
47 
49 
50 #endif // !STXXL_COMMON_IS_SORTED_HEADER
#define STXXL_BEGIN_NAMESPACE
Definition: namespace.h:16
bool is_sorted(ForwardIterator first, ForwardIterator last, StrictWeakOrdering comp)
Definition: is_sorted.h:24
#define STXXL_END_NAMESPACE
Definition: namespace.h:17