]> git.lyx.org Git - lyx.git/blob - src/support/lyxalgo.h
79799011060d5443ed897867fda58e5b3d7eeae0
[lyx.git] / src / support / lyxalgo.h
1 // -*- C++ -*-
2
3 #ifndef LYX_ALGO_H
4 #define LYX_ALGO_H
5
6 // Both these functions should ideally be placed into namespace lyx.
7 // Also the using std::less should not be used.
8
9 //namespace lyx {
10
11 /// Returns true if the sequence first,last is sorted, false if not.
12 template <class For>
13 bool sorted(For first, For last)
14 {
15         if (first == last) return true;
16         For tmp = first;
17         while (++tmp != last) {
18                 if (*tmp < *first++) return false;
19         }
20         return true;
21 }
22
23 /// Cmp is the same Cmp as you would pass to std::sort.
24 template <class For, class Cmp>
25 bool sorted(For first, For last, Cmp cmp)
26 {
27         if (first == last) return true;
28         For tmp = first;
29         while (++tmp != last) {
30                 if (cmp(*tmp, *first++)) return false;
31         }
32         return true;
33 }
34
35 // }  // end of namespace lyx
36 #endif