Merged revisions 151950:152181 from trunk.
[official-gcc.git] / libstdc++-v3 / include / parallel / checkers.h
blob70cc949e3fed58fc119ed80796cca178c5a52798
1 // -*- C++ -*-
3 // Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc.
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
8 // Foundation; either version 3, or (at your option) any later
9 // version.
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.
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.
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/>.
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.
30 // Written by Johannes Singler.
32 #ifndef _GLIBCXX_PARALLEL_CHECKERS_H
33 #define _GLIBCXX_PARALLEL_CHECKERS_H 1
35 #include <functional>
36 #include <cstdio>
37 #include <bits/stl_algobase.h>
39 namespace __gnu_parallel
41 /**
42 * @brief Check whether @__c [__begin, @__c __end) is sorted according
43 * to @__c __comp.
44 * @param __begin Begin iterator of sequence.
45 * @param __end End iterator of sequence.
46 * @param __comp Comparator.
47 * @return @__c true if sorted, @__c false otherwise.
49 template<typename _IIter, typename _Compare>
50 bool
51 __is_sorted(_IIter __begin, _IIter __end, _Compare __comp)
53 if (__begin == __end)
54 return true;
56 _IIter __current(__begin), __recent(__begin);
58 unsigned long long __position = 1;
59 for (__current++; __current != __end; __current++)
61 if (__comp(*__current, *__recent))
63 return false;
65 __recent = __current;
66 __position++;
69 return true;
72 #endif /* _GLIBCXX_PARALLEL_CHECKERS_H */