Explicitly link with libatomic when needed.
[official-gcc.git] / libstdc++-v3 / testsuite / 25_algorithms / unique / constrained.cc
blobe863a601dddf1c6dd702d53335d2a0b6e3a1f9a2
1 // Copyright (C) 2020 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 // { dg-options "-std=gnu++2a" }
19 // { dg-do run { target c++2a } }
21 #include <list>
22 #include <algorithm>
23 #include <testsuite_hooks.h>
24 #include <testsuite_iterators.h>
26 using __gnu_test::test_container;
27 using __gnu_test::test_range;
28 using __gnu_test::input_iterator_wrapper;
29 using __gnu_test::forward_iterator_wrapper;
32 namespace ranges = std::ranges;
34 struct X
36 int i;
39 void
40 test01()
43 X x[6] = { {2}, {2}, {6}, {8}, {2}, {11} };
44 const int y[5] = { {2}, {6}, {8}, {2}, {11} };
45 test_container<X, forward_iterator_wrapper> cx(x);
46 auto res = ranges::unique(cx, {}, &X::i);
47 VERIFY( res.end() == cx.end() );
48 VERIFY( ranges::equal(cx.begin(), res.begin(), y, y+5, {}, &X::i) );
52 X x[6] = { {2}, {2}, {6}, {8}, {2}, {11} };
53 const int y[5] = { {2}, {6}, {8}, {2}, {11} };
54 test_range<X, forward_iterator_wrapper> rx(x);
55 auto res = ranges::unique(rx, {}, &X::i);
56 VERIFY( res.end() == rx.end() );
57 VERIFY( ranges::equal(rx.begin(), res.begin(), y, y+5, {}, &X::i) );
61 constexpr bool
62 test02()
64 int x[2] = {2, 2};
65 const int y[1] = {2};
66 auto res = ranges::unique(x);
67 return ranges::equal(x, res.begin(), y, y+1, ranges::equal_to{});
70 /* The following is adapted from 25_algorithms/unique/2.cc. */
72 namespace two_dot_cc
74 const int T1[] = {1, 4, 4, 6, 1, 2, 2, 3, 1, 6, 6, 6, 5, 7, 5, 4, 4};
75 const int T2[] = {1, 1, 1, 2, 2, 1, 1, 7, 6, 6, 7, 8, 8, 8, 8, 9, 9};
76 const int N = sizeof(T1) / sizeof(int);
78 const int A1[] = {1, 4, 6, 1, 2, 3, 1, 6, 5, 7, 5, 4};
79 const int A2[] = {1, 4, 4, 6, 6, 6, 6, 7};
80 const int A3[] = {1, 1, 1};
82 const int B1[] = {1, 2, 1, 7, 6, 7, 8, 9};
83 const int B2[] = {1, 1, 1, 2, 2, 7, 7, 8, 8, 8, 8, 9, 9};
84 const int B3[] = {9, 9, 8, 8, 8, 8, 7, 6, 6, 1, 1, 1, 1, 1};
86 void test01()
88 using namespace std;
90 list<int>::iterator pos;
92 list<int> coll(T1, T1 + N);
93 pos = ranges::unique(coll.begin(), coll.end()).begin();
94 VERIFY( equal(coll.begin(), pos, A1) );
96 list<int> coll2(T2, T2 + N);
97 pos = ranges::unique(coll2.begin(), coll2.end()).begin();
98 VERIFY( equal(coll2.begin(), pos, B1) );
101 void test02()
103 using namespace std;
105 list<int>::iterator pos;
107 list<int> coll(T1, T1 + N);
108 pos = ranges::unique(coll.begin(), coll.end(), greater<int>()).begin();
109 VERIFY( equal(coll.begin(), pos, A2) );
111 list<int> coll2(T2, T2 + N);
112 pos = ranges::unique(coll2.begin(), coll2.end(), greater<int>()).begin();
113 VERIFY( equal(coll2.begin(), pos, B2) );
116 void test03()
118 using namespace std;
120 list<int>::iterator pos;
122 list<int> coll(T1, T1 + N);
123 pos = ranges::unique(coll.begin(), coll.end(), less<int>()).begin();
124 VERIFY( equal(coll.begin(), pos, A3) );
126 list<int> coll2(T2, T2 + N);
127 reverse(coll2.begin(), coll2.end());
128 pos = ranges::unique(coll2.begin(), coll2.end(), less<int>()).begin();
129 VERIFY( equal(coll2.begin(), pos, B3) );
131 } // namespace two_dot_cc
133 int main()
135 test01();
136 static_assert(test02());
138 two_dot_cc::test01();
139 two_dot_cc::test02();
140 two_dot_cc::test03();
142 return 0;