]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/25_algorithms/unique/2.cc
re PR c++/59378 (Internal compiler error when using __builtin_shuffle in a template...
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 25_algorithms / unique / 2.cc
1 // 2003-10-14 Paolo Carlini <pcarlini@unitus.it>
2
3 // Copyright (C) 2003-2013 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
9 // any later version.
10
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
19
20 // 25.2.8 [lib.alg.unique] Unique
21
22 #include <list>
23 #include <algorithm>
24 #include <functional>
25 #include <testsuite_hooks.h>
26
27 const int T1[] = {1, 4, 4, 6, 1, 2, 2, 3, 1, 6, 6, 6, 5, 7, 5, 4, 4};
28 const int T2[] = {1, 1, 1, 2, 2, 1, 1, 7, 6, 6, 7, 8, 8, 8, 8, 9, 9};
29 const int N = sizeof(T1) / sizeof(int);
30
31 const int A1[] = {1, 4, 6, 1, 2, 3, 1, 6, 5, 7, 5, 4};
32 const int A2[] = {1, 4, 4, 6, 6, 6, 6, 7};
33 const int A3[] = {1, 1, 1};
34
35 const int B1[] = {1, 2, 1, 7, 6, 7, 8, 9};
36 const int B2[] = {1, 1, 1, 2, 2, 7, 7, 8, 8, 8, 8, 9, 9};
37 const int B3[] = {9, 9, 8, 8, 8, 8, 7, 6, 6, 1, 1, 1, 1, 1};
38
39 void test01()
40 {
41 bool test __attribute__((unused)) = true;
42 using namespace std;
43
44 list<int>::iterator pos;
45
46 list<int> coll(T1, T1 + N);
47 pos = unique(coll.begin(), coll.end());
48 VERIFY( equal(coll.begin(), pos, A1) );
49
50 list<int> coll2(T2, T2 + N);
51 pos = unique(coll2.begin(), coll2.end());
52 VERIFY( equal(coll2.begin(), pos, B1) );
53 }
54
55 void test02()
56 {
57 bool test __attribute__((unused)) = true;
58 using namespace std;
59
60 list<int>::iterator pos;
61
62 list<int> coll(T1, T1 + N);
63 pos = unique(coll.begin(), coll.end(), greater<int>());
64 VERIFY( equal(coll.begin(), pos, A2) );
65
66 list<int> coll2(T2, T2 + N);
67 pos = unique(coll2.begin(), coll2.end(), greater<int>());
68 VERIFY( equal(coll2.begin(), pos, B2) );
69 }
70
71 void test03()
72 {
73 bool test __attribute__((unused)) = true;
74 using namespace std;
75
76 list<int>::iterator pos;
77
78 list<int> coll(T1, T1 + N);
79 pos = unique(coll.begin(), coll.end(), less<int>());
80 VERIFY( equal(coll.begin(), pos, A3) );
81
82 list<int> coll2(T2, T2 + N);
83 reverse(coll2.begin(), coll2.end());
84 pos = unique(coll2.begin(), coll2.end(), less<int>());
85 VERIFY( equal(coll2.begin(), pos, B3) );
86 }
87
88 int main()
89 {
90 test01();
91 test02();
92 test03();
93 return 0;
94 }