Improve atomic store implementation on hppa-linux.
[official-gcc.git] / libstdc++-v3 / testsuite / 25_algorithms / mismatch / 2.cc
blob4c7e508a0c7c4f9e2fb4fcb40d53aedfd22bf956
1 // Copyright (C) 2013-2021 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.10 [mismatch]
20 // { dg-do run { target c++14 } }
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;
29 typedef test_container<int, input_iterator_wrapper> Container;
31 int array1[] = {0, 1};
32 int array2[] = {1, 0};
33 int array3[] = {1, 0, 1};
35 struct equal_to
37 static int count;
39 bool operator()(int l, int r)
41 ++count;
42 return l == r;
44 } eq;
46 int equal_to::count = 0;
48 bool __attribute__((unused)) test = false;
50 void test1()
52 // empty ranges
53 Container con1(array1, array1);
54 Container con2(array2, array2);
55 auto res = std::mismatch(con1.begin(), con1.end(), con2.begin(), con2.end());
56 VERIFY( res.first.ptr == array1 );
57 VERIFY( res.second.ptr == array2 );
58 res = std::mismatch(con1.begin(), con1.end(), con2.begin(), con2.end(), eq);
59 VERIFY( res.first.ptr == array1 );
60 VERIFY( res.second.ptr == array2 );
61 VERIFY( equal_to::count == 0 );
64 void test2()
66 // first range empty, second non-empty
67 Container con1(array1, array1);
68 Container con2(array2, array2 + 2);
69 auto res = std::mismatch(con1.begin(), con1.end(), con2.begin(), con2.end());
70 VERIFY( res.first.ptr == array1 );
71 VERIFY( res.second.ptr == array2 );
73 res = std::mismatch(con1.begin(), con1.end(), con2.begin(), con2.end(), eq);
74 VERIFY( res.first.ptr == array1 );
75 VERIFY( res.second.ptr == array2 );
76 VERIFY( equal_to::count == 0 );
79 void test3()
81 // first range non-empty, second empty
82 Container con1(array1, array1 + 2);
83 Container con2(array2, array2);
84 auto res = std::mismatch(con1.begin(), con1.end(), con2.begin(), con2.end());
85 VERIFY( res.first.ptr == array1 );
86 VERIFY( res.second.ptr == array2 );
88 res = std::mismatch(con1.begin(), con1.end(), con2.begin(), con2.end(), eq);
89 VERIFY( res.first.ptr == array1 );
90 VERIFY( res.second.ptr == array2 );
91 VERIFY( equal_to::count == 0 );
94 void test4()
96 // non-empty, mismatching ranges
97 Container con1(array1, array1 + 2);
98 Container con2(array2, array2 + 2);
99 auto res = std::mismatch(con1.begin(), con1.end(), con2.begin(), con2.end());
100 VERIFY( res.first.ptr == array1 );
101 VERIFY( res.second.ptr == array2 );
103 con1.bounds.first = array1;
104 con2.bounds.first = array2;
105 res = std::mismatch(con1.begin(), con1.end(), con2.begin(), con2.end(), eq);
106 VERIFY( res.first.ptr == array1 );
107 VERIFY( res.second.ptr == array2 );
108 VERIFY( equal_to::count == 1 );
109 equal_to::count = 0;
112 void test5()
114 // non-empty, matching ranges
115 Container con3(array3, array3 + 2);
116 Container con2(array2, array2 + 2);
117 auto res = std::mismatch(con3.begin(), con3.end(), con2.begin(), con2.end());
118 VERIFY( res.first.ptr == array3 + 2 );
119 VERIFY( res.second.ptr == array2 + 2 );
121 con3.bounds.first = array3;
122 con2.bounds.first = array2;
123 res = std::mismatch(con3.begin(), con3.end(), con2.begin(), con2.end(), eq);
124 VERIFY( res.first.ptr == array3 + 2 );
125 VERIFY( res.second.ptr == array2 + 2 );
126 VERIFY( equal_to::count == 2 );
127 equal_to::count = 0;
130 void test6()
132 // non-empty, matching sub-ranges, first range longer
133 Container con3(array3, array3 + 3);
134 Container con2(array2, array2 + 2);
135 auto res = std::mismatch(con3.begin(), con3.end(), con2.begin(), con2.end());
136 VERIFY( res.first.ptr == array3 + 2 );
137 VERIFY( res.second.ptr == array2 + 2 );
139 con3.bounds.first = array3;
140 con2.bounds.first = array2;
141 res = std::mismatch(con3.begin(), con3.end(), con2.begin(), con2.end(), eq);
142 VERIFY( res.first.ptr == array3 + 2 );
143 VERIFY( res.second.ptr == array2 + 2 );
144 VERIFY( equal_to::count == 2 );
145 equal_to::count = 0;
148 void test7()
150 // non-empty, matching sub-ranges, second range longer
151 Container con3(array3, array3 + 3);
152 Container con2(array2, array2 + 2);
153 auto res = std::mismatch(con2.begin(), con2.end(), con3.begin(), con3.end());
154 VERIFY( res.first.ptr == array2 + 2 );
155 VERIFY( res.second.ptr == array3 + 2 );
157 con3.bounds.first = array3;
158 con2.bounds.first = array2;
159 res = std::mismatch(con2.begin(), con2.end(), con3.begin(), con3.end(), eq);
160 VERIFY( res.first.ptr == array2 + 2 );
161 VERIFY( res.second.ptr == array3 + 2 );
162 VERIFY( equal_to::count == 2 );
163 equal_to::count = 0;
166 int main()
168 test1();
169 test2();
170 test3();
171 test4();
172 test5();
173 test6();
174 test7();