]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/25_algorithms/unique/moveable.cc
1 // { dg-do run { target c++11 } }
3 // Copyright (C) 2005-2016 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 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};
42 const int N
= sizeof(intarray1
) / sizeof(int);
47 std::copy(intarray1
,intarray1
+ N
, T1
);
48 std::copy(intarray2
,intarray2
+ N
, T2
);
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};
53 Container
con(T1
, T1
+ N
);
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
] );
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
] );
65 bool are_equal(const rvalstruct
& rhs
, const rvalstruct
& lhs
)
66 { return rhs
== lhs
; }
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};
73 const int N
= sizeof(intarray1
) / sizeof(int);
78 std::copy(intarray1
,intarray1
+ N
, T1
);
79 std::copy(intarray2
,intarray2
+ N
, T2
);
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};
84 Container
con(T1
, T1
+ N
);
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
] );
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
] );