]> git.lyx.org Git - lyx.git/blob - src/support/lyxalgo.h
Move Lexer to support/ directory (and lyx::support namespace)
[lyx.git] / src / support / lyxalgo.h
1 // -*- C++ -*-
2 /**
3  * \file lyxalgo.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Lars Gullik Bjønnes
8  *
9  * Full author contact details are available in file CREDITS.
10  *
11  * A variety of useful templates.
12  */
13
14 #ifndef LYX_ALGO_H
15 #define LYX_ALGO_H
16
17 namespace lyx {
18
19
20 /// Returns true if the sequence first,last is sorted, false if not.
21 template <class For>
22 bool sorted(For first, For last)
23 {
24         if (first == last) return true;
25         For tmp = first;
26         while (++tmp != last) {
27                 if (*tmp < *first++) return false;
28         }
29         return true;
30 }
31
32
33 /// Cmp is the same Cmp as you would pass to std::sort.
34 template <class For, class Cmp>
35 bool sorted(For first, For last, Cmp cmp)
36 {
37         if (first == last) return true;
38         For tmp = first;
39         while (++tmp != last) {
40                 if (cmp(*tmp, *first++)) return false;
41         }
42         return true;
43 }
44
45
46 } // namespace lyx
47
48 #endif // LYX_ALGO_H