Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / libstdc++-v3 / testsuite / 25_algorithms / search_n / iterator.cc
blob7aeaac34b0b99732bd85dd62e221801ec1eee9bf
1 // Copyright (C) 2004 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 2, or (at your option)
7 // any later version.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING. If not, write to the Free
16 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
17 // USA.
19 // 25 algorithms, search_n
21 #include <algorithm>
22 #include <functional>
23 #include <testsuite_hooks.h>
24 #include <testsuite_iterators.h>
26 #define TEST_DEPTH 14
27 int array1[11] = {0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0};
28 int array2[TEST_DEPTH];
30 bool
31 pred(int i, int j)
33 return i == j;
36 bool
37 lexstep(int* start, int length)
39 int i = 0;
40 int carry = 1;
41 while(i < length && carry)
43 if(start[i] == 1)
44 start[i] = 0;
45 else
47 start[i] = 1;
48 carry = 0;
50 i++;
52 return !carry;
55 using __gnu_test::test_container;
56 using __gnu_test::random_access_iterator_wrapper;
57 using __gnu_test::bidirectional_iterator_wrapper;
58 using __gnu_test::forward_iterator_wrapper;
60 int main() {
61 test_container<int,forward_iterator_wrapper> con(array1,array1 + 10);
62 VERIFY(search_n(con.end(), con.end(), 0, 1) == con.end());
63 VERIFY(search_n(con.end(), con.end(), 1, 1) == con.end());
64 VERIFY(search_n(con.begin(), con.end(), 1, 1).ptr == array1 + 1);
65 VERIFY(search_n(con.begin(), con.end(), 2, 1).ptr == array1 + 4);
66 VERIFY(search_n(con.begin(), con.end(), 3, 1).ptr == array1 + 7);
67 VERIFY(search_n(con.begin(), con.end(), 3, 0) == con.end());
69 // Now do a brute-force comparison of the different types
70 for(int i = 0; i < TEST_DEPTH; i++)
72 for(int j = 0; j < i; j++)
73 array2[i] = 0;
74 do {
75 for(int j = 0; j < i; j++)
77 test_container<int, forward_iterator_wrapper>
78 forwardcon(array2, array2 + i);
79 test_container<int, random_access_iterator_wrapper>
80 randomcon(array2, array2 + i);
81 test_container<int, bidirectional_iterator_wrapper>
82 bidircon(array2, array2 + i);
84 int* t1 = search_n(forwardcon.begin(),
85 forwardcon.end(), j, 1).ptr;
86 int* t2 = search_n(forwardcon.begin(),
87 forwardcon.end(), j, 1, pred).ptr;
88 int* t3 = search_n(bidircon.begin(),
89 bidircon.end(), j, 1).ptr;
90 int* t4 = search_n(bidircon.begin(),
91 bidircon.end(), j, 1, pred).ptr;
92 int* t5 = search_n(randomcon.begin(),
93 randomcon.end(), j, 1).ptr;
94 int* t6 = search_n(randomcon.begin(),
95 randomcon.end(), j, 1, pred).ptr;
96 VERIFY((t1 == t2) && (t2 == t3) && (t3 == t4) &&
97 (t4 == t5) && (t5 == t6));
100 while(lexstep(array2, i));
102 return 0;