]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/25_algorithms/unique/moveable.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 25_algorithms / unique / moveable.cc
1 // { dg-do run { target c++11 } }
2
3 // Copyright (C) 2005-2023 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 #undef _GLIBCXX_CONCEPT_CHECKS
23
24 #include <vector>
25 #include <algorithm>
26 #include <functional>
27 #include <testsuite_hooks.h>
28 #include <testsuite_iterators.h>
29 #include <testsuite_rvalref.h>
30
31 using __gnu_test::test_container;
32 using __gnu_test::forward_iterator_wrapper;
33 using __gnu_test::rvalstruct;
34
35 typedef test_container<rvalstruct, forward_iterator_wrapper> Container;
36
37 void test01()
38 {
39 int intarray1[] = {1, 4, 4, 6, 1, 2, 2, 3, 1, 6, 6, 6, 5, 7, 5, 4, 4};
40 int intarray2[] = {1, 1, 1, 2, 2, 1, 1, 7, 6, 6, 7, 8, 8, 8, 8, 9, 9};
41
42 const int N = sizeof(intarray1) / sizeof(int);
43
44 rvalstruct T1[N];
45 rvalstruct T2[N];
46
47 std::copy(intarray1,intarray1 + N, T1);
48 std::copy(intarray2,intarray2 + N, T2);
49
50 const int A1[] = {1, 4, 6, 1, 2, 3, 1, 6, 5, 7, 5, 4};
51 const int B1[] = {1, 2, 1, 7, 6, 7, 8, 9};
52
53 Container con(T1, T1 + N);
54
55 VERIFY( std::unique(con.begin(), con.end()).ptr - T1 == 12 );
56 for(int i = 0; i < 12; ++i)
57 VERIFY( T1[i].val == A1[i] );
58
59 Container con2(T2, T2 + N);
60 VERIFY( std::unique(con2.begin(), con2.end()).ptr - T2 == 8 );
61 for(int i = 0; i < 8; ++i)
62 VERIFY( T2[i].val == B1[i] );
63 }
64
65 bool are_equal(const rvalstruct& rhs, const rvalstruct& lhs)
66 { return rhs == lhs; }
67
68 void test02()
69 {
70 int intarray1[] = {1, 4, 4, 6, 1, 2, 2, 3, 1, 6, 6, 6, 5, 7, 5, 4, 4};
71 int intarray2[] = {1, 1, 1, 2, 2, 1, 1, 7, 6, 6, 7, 8, 8, 8, 8, 9, 9};
72
73 const int N = sizeof(intarray1) / sizeof(int);
74
75 rvalstruct T1[N];
76 rvalstruct T2[N];
77
78 std::copy(intarray1,intarray1 + N, T1);
79 std::copy(intarray2,intarray2 + N, T2);
80
81 const int A1[] = {1, 4, 6, 1, 2, 3, 1, 6, 5, 7, 5, 4};
82 const int B1[] = {1, 2, 1, 7, 6, 7, 8, 9};
83
84 Container con(T1, T1 + N);
85
86 VERIFY( std::unique(con.begin(), con.end(), are_equal).ptr - T1 == 12 );
87 for(int i = 0; i < 12; ++i)
88 VERIFY( T1[i].val == A1[i] );
89
90 Container con2(T2, T2 + N);
91 VERIFY( std::unique(con2.begin(), con2.end(), are_equal).ptr - T2 == 8 );
92 for(int i = 0; i < 8; ++i)
93 VERIFY( T2[i].val == B1[i] );
94 }
95
96 int main()
97 {
98 test01();
99 test02();
100 return 0;
101 }