]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/25_algorithms/unique/moveable.cc
1 // { dg-options "-std=gnu++0x" }
3 // Copyright (C) 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
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)
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.
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/>.
20 // 25.2.8 [lib.alg.unique] Unique
22 #undef _GLIBCXX_CONCEPT_CHECKS
27 #include <testsuite_hooks.h>
28 #include <testsuite_iterators.h>
29 #include <testsuite_rvalref.h>
31 using __gnu_test::test_container
;
32 using __gnu_test::forward_iterator_wrapper
;
33 using __gnu_test::rvalstruct
;
35 typedef test_container
<rvalstruct
, forward_iterator_wrapper
> Container
;
39 bool test
__attribute__((unused
)) = true;
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};
44 const int N
= sizeof(intarray1
) / sizeof(int);
49 std::copy(intarray1
,intarray1
+ N
, T1
);
50 std::copy(intarray2
,intarray2
+ N
, T2
);
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};
55 Container
con(T1
, T1
+ N
);
57 VERIFY( std::unique(con
.begin(), con
.end()).ptr
- T1
== 12 );
58 for(int i
= 0; i
< 12; ++i
)
59 VERIFY( T1
[i
].val
== A1
[i
] );
61 Container
con2(T2
, T2
+ N
);
62 VERIFY( std::unique(con2
.begin(), con2
.end()).ptr
- T2
== 8 );
63 for(int i
= 0; i
< 8; ++i
)
64 VERIFY( T2
[i
].val
== B1
[i
] );
67 bool are_equal(const rvalstruct
& rhs
, const rvalstruct
& lhs
)
68 { return rhs
== lhs
; }
72 bool test
__attribute__((unused
)) = true;
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};
77 const int N
= sizeof(intarray1
) / sizeof(int);
82 std::copy(intarray1
,intarray1
+ N
, T1
);
83 std::copy(intarray2
,intarray2
+ N
, T2
);
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};
88 Container
con(T1
, T1
+ N
);
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
] );
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
] );