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