]>
Commit | Line | Data |
---|---|---|
f5783e34 CJ |
1 | // { dg-options "-std=gnu++0x" } |
2 | ||
aa118a03 | 3 | // Copyright (C) 2005-2014 Free Software Foundation, Inc. |
f5783e34 CJ |
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 | |
748086b7 | 8 | // Free Software Foundation; either version 3, or (at your option) |
f5783e34 CJ |
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 | |
748086b7 JJ |
17 | // with this library; see the file COPYING3. If not see |
18 | // <http://www.gnu.org/licenses/>. | |
f5783e34 CJ |
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 | bool test __attribute__((unused)) = true; | |
40 | ||
41 | int intarray1[] = {1, 4, 4, 6, 1, 2, 2, 3, 1, 6, 6, 6, 5, 7, 5, 4, 4}; | |
42 | int intarray2[] = {1, 1, 1, 2, 2, 1, 1, 7, 6, 6, 7, 8, 8, 8, 8, 9, 9}; | |
43 | ||
44 | const int N = sizeof(intarray1) / sizeof(int); | |
45 | ||
46 | rvalstruct T1[N]; | |
47 | rvalstruct T2[N]; | |
48 | ||
49 | std::copy(intarray1,intarray1 + N, T1); | |
50 | std::copy(intarray2,intarray2 + N, T2); | |
51 | ||
52 | const int A1[] = {1, 4, 6, 1, 2, 3, 1, 6, 5, 7, 5, 4}; | |
53 | const int B1[] = {1, 2, 1, 7, 6, 7, 8, 9}; | |
54 | ||
55 | Container con(T1, T1 + N); | |
56 | ||
01bbe151 | 57 | VERIFY( std::unique(con.begin(), con.end()).ptr - T1 == 12 ); |
f5783e34 | 58 | for(int i = 0; i < 12; ++i) |
01bbe151 | 59 | VERIFY( T1[i].val == A1[i] ); |
f5783e34 CJ |
60 | |
61 | Container con2(T2, T2 + N); | |
01bbe151 | 62 | VERIFY( std::unique(con2.begin(), con2.end()).ptr - T2 == 8 ); |
f5783e34 | 63 | for(int i = 0; i < 8; ++i) |
01bbe151 | 64 | VERIFY( T2[i].val == B1[i] ); |
f5783e34 CJ |
65 | } |
66 | ||
01bbe151 CJ |
67 | bool are_equal(const rvalstruct& rhs, const rvalstruct& lhs) |
68 | { return rhs == lhs; } | |
69 | ||
70 | void test02() | |
71 | { | |
72 | bool test __attribute__((unused)) = true; | |
73 | ||
74 | int intarray1[] = {1, 4, 4, 6, 1, 2, 2, 3, 1, 6, 6, 6, 5, 7, 5, 4, 4}; | |
75 | int intarray2[] = {1, 1, 1, 2, 2, 1, 1, 7, 6, 6, 7, 8, 8, 8, 8, 9, 9}; | |
76 | ||
77 | const int N = sizeof(intarray1) / sizeof(int); | |
78 | ||
79 | rvalstruct T1[N]; | |
80 | rvalstruct T2[N]; | |
81 | ||
82 | std::copy(intarray1,intarray1 + N, T1); | |
83 | std::copy(intarray2,intarray2 + N, T2); | |
84 | ||
85 | const int A1[] = {1, 4, 6, 1, 2, 3, 1, 6, 5, 7, 5, 4}; | |
86 | const int B1[] = {1, 2, 1, 7, 6, 7, 8, 9}; | |
87 | ||
88 | Container con(T1, T1 + N); | |
89 | ||
90 | VERIFY( std::unique(con.begin(), con.end(), are_equal).ptr - T1 == 12 ); | |
91 | for(int i = 0; i < 12; ++i) | |
92 | VERIFY( T1[i].val == A1[i] ); | |
93 | ||
94 | Container con2(T2, T2 + N); | |
95 | VERIFY( std::unique(con2.begin(), con2.end(), are_equal).ptr - T2 == 8 ); | |
96 | for(int i = 0; i < 8; ++i) | |
97 | VERIFY( T2[i].val == B1[i] ); | |
98 | } | |
f5783e34 CJ |
99 | |
100 | int main() | |
101 | { | |
102 | test01(); | |
01bbe151 | 103 | test02(); |
f5783e34 CJ |
104 | return 0; |
105 | } |