]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/include/parallel/checkers.h
3 // Copyright (C) 2007, 2008 Free Software Foundation, Inc.
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 2, or (at your option) any later
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 // You should have received a copy of the GNU General Public License
17 // along with this library; see the file COPYING. If not, write to
18 // the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
19 // MA 02111-1307, USA.
21 // As a special exception, you may use this file as part of a free
22 // software library without restriction. Specifically, if other files
23 // instantiate templates or use macros or inline functions from this
24 // file, or you compile this file and link it with other files to
25 // produce an executable, this file does not by itself cause the
26 // resulting executable to be covered by the GNU General Public
27 // License. This exception does not however invalidate any other
28 // reasons why the executable file might be covered by the GNU General
31 /** @file parallel/checkers.h
32 * @brief Routines for checking the correctness of algorithm results.
33 * This file is a GNU parallel extension to the Standard C++ Library.
36 // Written by Johannes Singler.
38 #ifndef _GLIBCXX_PARALLEL_CHECKERS_H
39 #define _GLIBCXX_PARALLEL_CHECKERS_H 1
43 #include <bits/stl_algobase.h>
45 namespace __gnu_parallel
48 * @brief Check whether @c [begin, @c end) is sorted according to @c comp.
49 * @param begin Begin iterator of sequence.
50 * @param end End iterator of sequence.
51 * @param comp Comparator.
52 * @return @c true if sorted, @c false otherwise.
54 // XXX Comparator default template argument
55 template<typename InputIterator
, typename Comparator
>
57 is_sorted(InputIterator begin
, InputIterator end
,
59 = std::less
<typename
std::iterator_traits
<InputIterator
>::
65 InputIterator
current(begin
), recent(begin
);
67 unsigned long long position
= 1;
68 for (current
++; current
!= end
; current
++)
70 if (comp(*current
, *recent
))
72 printf("is_sorted: check failed before position %i.\n",
84 * @brief Check whether @c [begin, @c end) is sorted according to @c comp.
85 * Prints the position in case an unordered pair is found.
86 * @param begin Begin iterator of sequence.
87 * @param end End iterator of sequence.
88 * @param first_failure The first failure is returned in this variable.
89 * @param comp Comparator.
90 * @return @c true if sorted, @c false otherwise.
92 // XXX Comparator default template argument
93 template<typename InputIterator
, typename Comparator
>
95 is_sorted_failure(InputIterator begin
, InputIterator end
,
96 InputIterator
& first_failure
,
98 = std::less
<typename
std::iterator_traits
<InputIterator
>::
104 InputIterator
current(begin
), recent(begin
);
106 unsigned long long position
= 1;
107 for (current
++; current
!= end
; current
++)
109 if (comp(*current
, *recent
))
111 first_failure
= current
;
112 printf("is_sorted: check failed before position %lld.\n",
125 * @brief Check whether @c [begin, @c end) is sorted according to @c comp.
126 * Prints all unordered pair, including the surrounding two elements.
127 * @param begin Begin iterator of sequence.
128 * @param end End iterator of sequence.
129 * @param comp Comparator.
130 * @return @c true if sorted, @c false otherwise.
132 template<typename InputIterator
, typename Comparator
>
134 // XXX Comparator default template argument
135 is_sorted_print_failures(InputIterator begin
, InputIterator end
,
137 = std::less
<typename
std::iterator_traits
138 <InputIterator
>::value_type
>())
143 InputIterator
recent(begin
);
146 for (InputIterator
pos(begin
+ 1); pos
!= end
; pos
++)
148 if (comp(*pos
, *recent
))
150 printf("%ld: %d %d %d %d\n", pos
- begin
, *(pos
- 2),
151 *(pos
- 1), *pos
, *(pos
+ 1));
160 #endif /* _GLIBCXX_PARALLEL_CHECKERS_H */