* include/bits/stl_algo.h (is_permutation): Add overloads from N3671.
[official-gcc.git] / libstdc++-v3 / testsuite / 25_algorithms / equal / 2.cc
blob012609f7fe86e5c1e47ea12f37e7cc99d59d91a9
1 // Copyright (C) 2013 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 3, 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 COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
18 // 25.2.11 [alg.equal]
20 // { dg-options "-std=gnu++1y" }
22 #include <algorithm>
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};
36 struct equal_to
38 static int count;
40 bool operator()(int l, int r)
42 ++count;
43 return l == r;
45 } eq;
47 int equal_to::count = 0;
49 bool __attribute__((unused)) test = false;
51 void test1()
53 const Container con1(array1, array1);
54 const Container con2(array2, array2);
56 auto c1 = con1;
57 auto c2 = con2;
58 VERIFY( std::equal(c1.begin(), c1.end(), c2.begin(), c2.end()) );
59 VERIFY( equal_to::count == 0 );
61 c1 = con1;
62 c2 = con2;
63 VERIFY( std::equal(c1.begin(), c1.end(), c2.begin(), c2.end(), eq) );
64 VERIFY( equal_to::count == 0 );
67 void test2()
69 const Container con1(array1, array1 + 0);
70 const Container con2(array2, array2 + 2);
72 auto c1 = con1;
73 auto c2 = con2;
74 VERIFY( !std::equal(c1.begin(), c1.end(), c2.begin(), c2.end()) );
76 c1 = con1;
77 c2 = con2;
78 VERIFY( !std::equal(c1.begin(), c1.end(), c2.begin(), c2.end(), eq) );
79 VERIFY( equal_to::count == 0 );
81 c1 = con1;
82 c2 = con2;
83 VERIFY( !std::equal(c2.begin(), c2.end(), c1.begin(), c1.end()) );
85 c1 = con1;
86 c2 = con2;
87 VERIFY( !std::equal(c2.begin(), c2.end(), c1.begin(), c1.end(), eq) );
88 VERIFY( equal_to::count == 0 );
91 void test3()
93 const Container con1(array1, array1 + 2);
94 const Container con2(array2, array2 + 2);
96 auto c1 = con1;
97 auto c2 = con2;
98 VERIFY( !std::equal(c1.begin(), c1.end(), c2.begin(), c2.end()) );
100 c1 = con1;
101 c2 = con2;
102 VERIFY( !std::equal(c1.begin(), c1.end(), c2.begin(), c2.end(), eq) );
103 VERIFY( equal_to::count == 1 );
104 equal_to::count = 0;
106 c1 = con1;
107 c2 = con2;
108 VERIFY( !std::equal(c2.begin(), c2.end(), c1.begin(), c1.end()) );
110 c1 = con1;
111 c2 = con2;
112 VERIFY( !std::equal(c2.begin(), c2.end(), c1.begin(), c1.end(), eq) );
113 VERIFY( equal_to::count == 1 );
114 equal_to::count = 0;
117 void test4()
119 const Container con3(array3, array3 + 2);
120 const Container con2(array2, array2 + 2);
122 auto c3 = con3;
123 auto c2 = con2;
124 VERIFY( std::equal(c3.begin(), c3.end(), c2.begin(), c2.end()) );
126 c3 = con3;
127 c2 = con2;
128 VERIFY( std::equal(c3.begin(), c3.end(), c2.begin(), c2.end(), eq) );
129 VERIFY( equal_to::count == 2 );
130 equal_to::count = 0;
132 c3 = con3;
133 c2 = con2;
134 VERIFY( std::equal(c2.begin(), c2.end(), c3.begin(), c3.end()) );
136 c3 = con3;
137 c2 = con2;
138 VERIFY( std::equal(c2.begin(), c2.end(), c3.begin(), c3.end(), eq) );
139 VERIFY( equal_to::count == 2 );
140 equal_to::count = 0;
143 void test5()
145 const Container con3(array3, array3 + 1);
146 const Container con2(array2, array2 + 2);
148 auto c3 = con3;
149 auto c2 = con2;
150 VERIFY( !std::equal(c3.begin(), c3.end(), c2.begin(), c2.end()) );
152 c3 = con3;
153 c2 = con2;
154 VERIFY( !std::equal(c3.begin(), c3.end(), c2.begin(), c2.end(), eq) );
155 VERIFY( equal_to::count == 1 );
156 equal_to::count = 0;
158 c3 = con3;
159 c2 = con2;
160 VERIFY( !std::equal(c2.begin(), c2.end(), c3.begin(), c3.end()) );
162 c3 = con3;
163 c2 = con2;
164 VERIFY( !std::equal(c2.begin(), c2.end(), c3.begin(), c3.end(), eq) );
165 VERIFY( equal_to::count == 1 );
166 equal_to::count = 0;
169 void test6()
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 );
185 int main()
187 test1();
188 test2();
189 test3();
190 test4();
191 test5();
192 test6();