1 // Copyright (C) 2005-2025 Free Software Foundation, Inc.
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 3, or (at your option)
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 COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
18 // 25.1.5 [lib.alg.search]
21 #include <testsuite_hooks.h>
22 #include <testsuite_iterators.h>
24 using __gnu_test::test_container
;
25 using __gnu_test::forward_iterator_wrapper
;
26 using __gnu_test::random_access_iterator_wrapper
;
29 typedef test_container
<int, forward_iterator_wrapper
> Container
;
30 typedef test_container
<int, random_access_iterator_wrapper
> RAcontainer
;
31 int array1
[] = {0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1};
32 int array2
[] = {0, 0, 0};
37 Container
con1(array1
, array1
);
38 Container
con2(array1
, array1
+ 1);
39 VERIFY(search(con1
.begin(), con1
.end(), con2
.begin(), con2
.end()).ptr
== array1
);
40 VERIFY(search(con2
.begin(), con2
.end(), con1
.begin(), con1
.end()).ptr
== array1
);
46 Container
con1(array1
, array1
+ 3);
47 Container
con2(array2
, array2
+ 3);
48 VERIFY(search(con1
.begin(), con1
.end(), con2
.begin(), con2
.end()).ptr
55 Container
con1(array1
+ 3, array1
+ 10);
56 Container
con2(array2
, array2
+ 3);
57 VERIFY(search(con1
.begin(), con1
.end(), con2
.begin(), con2
.end()).ptr
64 Container
con1(array1
, array1
+ 10);
65 Container
con2(array2
, array2
+ 1);
66 VERIFY(search(con1
.begin(), con1
.end(), con2
.begin(), con2
.end()).ptr
73 Container
con1(array1
+ 6, array1
+ 10);
74 Container
con2(array2
, array2
+ 1);
75 VERIFY(search(con1
.begin(), con1
.end(), con2
.begin(), con2
.end()).ptr
82 int array3
[]={2, 2, 1, 2, 3, 5};
83 int array4
[]={1, 2, 3, 4};
84 Container
con1(array3
, array3
+ 3);
85 Container
con2(array3
, array3
+ 4);
86 Container
con3(array3
, array3
+ 5);
87 Container
con4(array3
, array3
+ 6);
88 Container
endcon(array4
, array4
+ 4);
89 VERIFY(search(con1
.begin(), con1
.end(), endcon
.begin(), endcon
.end()).ptr
91 VERIFY(search(con2
.begin(), con2
.end(), endcon
.begin(), endcon
.end()).ptr
93 VERIFY(search(con3
.begin(), con3
.end(), endcon
.begin(), endcon
.end()).ptr
95 VERIFY(search(con4
.begin(), con4
.end(), endcon
.begin(), endcon
.end()).ptr
100 lexstep(int* start
, int length
)
104 while(i
< length
&& carry
)
122 for(int length1
= 0; length1
< 6; length1
++)
124 for(int length2
= 0; length2
< 6; length2
++)
126 std::fill_n(array1
, length1
, 0);
127 while(lexstep(array1
, length1
))
129 std::fill_n(array2
, length2
, 0);
130 while(lexstep(array2
, length2
))
132 Container
con1(array1
, array1
+ length1
);
133 Container
con2(array2
, array2
+ length2
);
134 RAcontainer
rcon1(array1
, array1
+ length1
);
135 RAcontainer
rcon2(array2
, array2
+ length2
);
136 VERIFY(search(con1
.begin(), con1
.end(), con2
.begin(),
138 search(rcon1
.begin(), rcon1
.end(), rcon2
.begin(),