1 // Copyright (C) 2013-2017 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.2.11 [alg.equal]
20 // { dg-do run { target c++14 } }
23 #include <testsuite_hooks.h>
24 #include <testsuite_iterators.h>
26 using __gnu_test::test_container
;
27 using __gnu_test::input_iterator_wrapper
;
28 using __gnu_test::random_access_iterator_wrapper
;
30 typedef test_container
<int, input_iterator_wrapper
> Container
;
31 typedef test_container
<int, random_access_iterator_wrapper
> RA_Container
;
32 int array1
[] = {0, 1};
33 int array2
[] = {1, 0};
34 int array3
[] = {1, 0};
40 bool operator()(int l
, int r
)
47 int equal_to::count
= 0;
49 bool __attribute__((unused
)) test
= false;
53 const Container
con1(array1
, array1
);
54 const Container
con2(array2
, array2
);
58 VERIFY( std::equal(c1
.begin(), c1
.end(), c2
.begin(), c2
.end()) );
59 VERIFY( equal_to::count
== 0 );
63 VERIFY( std::equal(c1
.begin(), c1
.end(), c2
.begin(), c2
.end(), eq
) );
64 VERIFY( equal_to::count
== 0 );
69 const Container
con1(array1
, array1
+ 0);
70 const Container
con2(array2
, array2
+ 2);
74 VERIFY( !std::equal(c1
.begin(), c1
.end(), c2
.begin(), c2
.end()) );
78 VERIFY( !std::equal(c1
.begin(), c1
.end(), c2
.begin(), c2
.end(), eq
) );
79 VERIFY( equal_to::count
== 0 );
83 VERIFY( !std::equal(c2
.begin(), c2
.end(), c1
.begin(), c1
.end()) );
87 VERIFY( !std::equal(c2
.begin(), c2
.end(), c1
.begin(), c1
.end(), eq
) );
88 VERIFY( equal_to::count
== 0 );
93 const Container
con1(array1
, array1
+ 2);
94 const Container
con2(array2
, array2
+ 2);
98 VERIFY( !std::equal(c1
.begin(), c1
.end(), c2
.begin(), c2
.end()) );
102 VERIFY( !std::equal(c1
.begin(), c1
.end(), c2
.begin(), c2
.end(), eq
) );
103 VERIFY( equal_to::count
== 1 );
108 VERIFY( !std::equal(c2
.begin(), c2
.end(), c1
.begin(), c1
.end()) );
112 VERIFY( !std::equal(c2
.begin(), c2
.end(), c1
.begin(), c1
.end(), eq
) );
113 VERIFY( equal_to::count
== 1 );
119 const Container
con3(array3
, array3
+ 2);
120 const Container
con2(array2
, array2
+ 2);
124 VERIFY( std::equal(c3
.begin(), c3
.end(), c2
.begin(), c2
.end()) );
128 VERIFY( std::equal(c3
.begin(), c3
.end(), c2
.begin(), c2
.end(), eq
) );
129 VERIFY( equal_to::count
== 2 );
134 VERIFY( std::equal(c2
.begin(), c2
.end(), c3
.begin(), c3
.end()) );
138 VERIFY( std::equal(c2
.begin(), c2
.end(), c3
.begin(), c3
.end(), eq
) );
139 VERIFY( equal_to::count
== 2 );
145 const Container
con3(array3
, array3
+ 1);
146 const Container
con2(array2
, array2
+ 2);
150 VERIFY( !std::equal(c3
.begin(), c3
.end(), c2
.begin(), c2
.end()) );
154 VERIFY( !std::equal(c3
.begin(), c3
.end(), c2
.begin(), c2
.end(), eq
) );
155 VERIFY( equal_to::count
== 1 );
160 VERIFY( !std::equal(c2
.begin(), c2
.end(), c3
.begin(), c3
.end()) );
164 VERIFY( !std::equal(c2
.begin(), c2
.end(), c3
.begin(), c3
.end(), eq
) );
165 VERIFY( equal_to::count
== 1 );
171 RA_Container
c3(array3
, array3
+ 1);
172 RA_Container
c2(array2
, array2
+ 2);
174 VERIFY( !std::equal(c3
.begin(), c3
.end(), c2
.begin(), c2
.end()) );
176 VERIFY( !std::equal(c3
.begin(), c3
.end(), c2
.begin(), c2
.end(), eq
) );
177 VERIFY( equal_to::count
== 0 );
179 VERIFY( !std::equal(c2
.begin(), c2
.end(), c3
.begin(), c3
.end()) );
181 VERIFY( !std::equal(c2
.begin(), c2
.end(), c3
.begin(), c3
.end(), eq
) );
182 VERIFY( equal_to::count
== 0 );