]>
Commit | Line | Data |
---|---|---|
c2ba9709 JS |
1 | // -*- C++ -*- |
2 | ||
a5544970 | 3 | // Copyright (C) 2007-2019 Free Software Foundation, Inc. |
c2ba9709 JS |
4 | // |
5 | // This file is part of the GNU ISO C++ Library. This library is free | |
6 | // software; you can redistribute it and/or modify it under the terms | |
7 | // of the GNU General Public License as published by the Free Software | |
748086b7 | 8 | // Foundation; either version 3, or (at your option) any later |
c2ba9709 JS |
9 | // version. |
10 | ||
11 | // This library is distributed in the hope that it will be useful, but | |
12 | // WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | // General Public License for more details. | |
15 | ||
748086b7 JJ |
16 | // Under Section 7 of GPL version 3, you are granted additional |
17 | // permissions described in the GCC Runtime Library Exception, version | |
18 | // 3.1, as published by the Free Software Foundation. | |
19 | ||
20 | // You should have received a copy of the GNU General Public License and | |
21 | // a copy of the GCC Runtime Library Exception along with this program; | |
22 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see | |
23 | // <http://www.gnu.org/licenses/>. | |
c2ba9709 JS |
24 | |
25 | /** @file parallel/checkers.h | |
26 | * @brief Routines for checking the correctness of algorithm results. | |
27 | * This file is a GNU parallel extension to the Standard C++ Library. | |
28 | */ | |
29 | ||
30 | // Written by Johannes Singler. | |
31 | ||
cbcd1e45 JS |
32 | #ifndef _GLIBCXX_PARALLEL_CHECKERS_H |
33 | #define _GLIBCXX_PARALLEL_CHECKERS_H 1 | |
c2ba9709 | 34 | |
c2ba9709 JS |
35 | #include <cstdio> |
36 | #include <bits/stl_algobase.h> | |
53567bbd | 37 | #include <bits/stl_function.h> |
c2ba9709 JS |
38 | |
39 | namespace __gnu_parallel | |
40 | { | |
41 | /** | |
8e32aa11 BK |
42 | * @brief Check whether @c [__begin, @c __end) is sorted according |
43 | * to @c __comp. | |
1acba85b JS |
44 | * @param __begin Begin iterator of sequence. |
45 | * @param __end End iterator of sequence. | |
46 | * @param __comp Comparator. | |
8e32aa11 | 47 | * @return @c true if sorted, @c false otherwise. |
c2ba9709 | 48 | */ |
1acba85b | 49 | template<typename _IIter, typename _Compare> |
531898c3 | 50 | bool |
0e505d53 | 51 | __is_sorted(_IIter __begin, _IIter __end, _Compare __comp) |
531898c3 | 52 | { |
1acba85b | 53 | if (__begin == __end) |
15ac3c72 | 54 | return true; |
531898c3 | 55 | |
1acba85b | 56 | _IIter __current(__begin), __recent(__begin); |
531898c3 | 57 | |
1acba85b JS |
58 | unsigned long long __position = 1; |
59 | for (__current++; __current != __end; __current++) | |
15ac3c72 JS |
60 | { |
61 | if (__comp(*__current, *__recent)) | |
62 | { | |
15ac3c72 JS |
63 | return false; |
64 | } | |
65 | __recent = __current; | |
66 | __position++; | |
67 | } | |
c2ba9709 | 68 | |
531898c3 PC |
69 | return true; |
70 | } | |
77d16198 | 71 | } |
c2ba9709 | 72 | |
cbcd1e45 | 73 | #endif /* _GLIBCXX_PARALLEL_CHECKERS_H */ |