]>
Commit | Line | Data |
---|---|---|
f5783e34 CJ |
1 | // { dg-options "-std=gnu++0x" } |
2 | ||
061217e9 | 3 | // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011 |
932f6f4a | 4 | // Free Software Foundation, Inc. |
f5783e34 CJ |
5 | // |
6 | // This file is part of the GNU ISO C++ Library. This library is free | |
7 | // software; you can redistribute it and/or modify it under the | |
8 | // terms of the GNU General Public License as published by the | |
748086b7 | 9 | // Free Software Foundation; either version 3, or (at your option) |
f5783e34 CJ |
10 | // any later version. |
11 | ||
12 | // This library is distributed in the hope that it will be useful, | |
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | // GNU General Public License for more details. | |
16 | ||
17 | // You should have received a copy of the GNU General Public License along | |
748086b7 JJ |
18 | // with this library; see the file COPYING3. If not see |
19 | // <http://www.gnu.org/licenses/>. | |
f5783e34 CJ |
20 | |
21 | // 25.2.8 [lib.alg.unique] Unique | |
22 | ||
23 | #undef _GLIBCXX_CONCEPT_CHECKS | |
24 | ||
25 | #include <vector> | |
26 | #include <algorithm> | |
27 | #include <functional> | |
28 | #include <testsuite_hooks.h> | |
29 | #include <testsuite_iterators.h> | |
30 | #include <testsuite_rvalref.h> | |
31 | ||
32 | using __gnu_test::test_container; | |
33 | using __gnu_test::forward_iterator_wrapper; | |
34 | using __gnu_test::rvalstruct; | |
35 | ||
36 | typedef test_container<rvalstruct, forward_iterator_wrapper> Container; | |
37 | ||
38 | void test01() | |
39 | { | |
40 | bool test __attribute__((unused)) = true; | |
41 | ||
42 | int intarray1[] = {1, 4, 4, 6, 1, 2, 2, 3, 1, 6, 6, 6, 5, 7, 5, 4, 4}; | |
43 | int intarray2[] = {1, 1, 1, 2, 2, 1, 1, 7, 6, 6, 7, 8, 8, 8, 8, 9, 9}; | |
44 | ||
45 | const int N = sizeof(intarray1) / sizeof(int); | |
46 | ||
47 | rvalstruct T1[N]; | |
48 | rvalstruct T2[N]; | |
49 | ||
50 | std::copy(intarray1,intarray1 + N, T1); | |
51 | std::copy(intarray2,intarray2 + N, T2); | |
52 | ||
53 | const int A1[] = {1, 4, 6, 1, 2, 3, 1, 6, 5, 7, 5, 4}; | |
54 | const int B1[] = {1, 2, 1, 7, 6, 7, 8, 9}; | |
55 | ||
56 | Container con(T1, T1 + N); | |
57 | ||
01bbe151 | 58 | VERIFY( std::unique(con.begin(), con.end()).ptr - T1 == 12 ); |
f5783e34 | 59 | for(int i = 0; i < 12; ++i) |
01bbe151 | 60 | VERIFY( T1[i].val == A1[i] ); |
f5783e34 CJ |
61 | |
62 | Container con2(T2, T2 + N); | |
01bbe151 | 63 | VERIFY( std::unique(con2.begin(), con2.end()).ptr - T2 == 8 ); |
f5783e34 | 64 | for(int i = 0; i < 8; ++i) |
01bbe151 | 65 | VERIFY( T2[i].val == B1[i] ); |
f5783e34 CJ |
66 | } |
67 | ||
01bbe151 CJ |
68 | bool are_equal(const rvalstruct& rhs, const rvalstruct& lhs) |
69 | { return rhs == lhs; } | |
70 | ||
71 | void test02() | |
72 | { | |
73 | bool test __attribute__((unused)) = true; | |
74 | ||
75 | int intarray1[] = {1, 4, 4, 6, 1, 2, 2, 3, 1, 6, 6, 6, 5, 7, 5, 4, 4}; | |
76 | int intarray2[] = {1, 1, 1, 2, 2, 1, 1, 7, 6, 6, 7, 8, 8, 8, 8, 9, 9}; | |
77 | ||
78 | const int N = sizeof(intarray1) / sizeof(int); | |
79 | ||
80 | rvalstruct T1[N]; | |
81 | rvalstruct T2[N]; | |
82 | ||
83 | std::copy(intarray1,intarray1 + N, T1); | |
84 | std::copy(intarray2,intarray2 + N, T2); | |
85 | ||
86 | const int A1[] = {1, 4, 6, 1, 2, 3, 1, 6, 5, 7, 5, 4}; | |
87 | const int B1[] = {1, 2, 1, 7, 6, 7, 8, 9}; | |
88 | ||
89 | Container con(T1, T1 + N); | |
90 | ||
91 | VERIFY( std::unique(con.begin(), con.end(), are_equal).ptr - T1 == 12 ); | |
92 | for(int i = 0; i < 12; ++i) | |
93 | VERIFY( T1[i].val == A1[i] ); | |
94 | ||
95 | Container con2(T2, T2 + N); | |
96 | VERIFY( std::unique(con2.begin(), con2.end(), are_equal).ptr - T2 == 8 ); | |
97 | for(int i = 0; i < 8; ++i) | |
98 | VERIFY( T2[i].val == B1[i] ); | |
99 | } | |
f5783e34 CJ |
100 | |
101 | int main() | |
102 | { | |
103 | test01(); | |
01bbe151 | 104 | test02(); |
f5783e34 CJ |
105 | return 0; |
106 | } |