1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
11 // template <class BinaryPred> void unique(BinaryPred pred); // before C++20
12 // template <class BinaryPred> size_type unique(BinaryPred pred); // C++20 and later
17 #include "test_macros.h"
18 #include "min_allocator.h"
26 PredLWG526 (int i
) : i_(i
) {};
27 ~PredLWG526() { i_
= -32767; }
28 bool operator() (const PredLWG526
&lhs
, const PredLWG526
&rhs
) const { return lhs
.i_
== rhs
.i_
; }
30 bool operator==(int i
) const { return i
== i_
;}
37 int a1
[] = {2, 1, 1, 4, 4, 4, 4, 3, 3};
38 int a2
[] = {2, 1, 4, 3};
39 typedef std::list
<int> L
;
40 L
c(a1
, a1
+sizeof(a1
)/sizeof(a1
[0]));
42 ASSERT_SAME_TYPE(L::size_type
, decltype(c
.unique(g
)));
43 assert(c
.unique(g
) == 5);
45 ASSERT_SAME_TYPE(void, decltype(c
.unique(g
)));
48 assert(c
== std::list
<int>(a2
, a2
+4));
52 int a1
[] = {1, 1, 1, 2, 3, 5, 5, 2, 11};
53 int a2
[] = {1, 2, 3, 5, 2, 11};
54 std::list
<PredLWG526
> c(a1
, a1
+ 9);
56 assert(c
.unique(std::ref(c
.front())) == 3);
58 c
.unique(std::ref(c
.front()));
60 assert(c
.size() == 6);
61 for (size_t i
= 0; i
< c
.size(); ++i
)
63 assert(c
.front() == a2
[i
]);
68 #if TEST_STD_VER >= 11
70 int a1
[] = {2, 1, 1, 4, 4, 4, 4, 3, 3};
71 int a2
[] = {2, 1, 4, 3};
72 std::list
<int, min_allocator
<int>> c(a1
, a1
+sizeof(a1
)/sizeof(a1
[0]));
74 assert(c
.unique(g
) == 5);
78 assert((c
== std::list
<int, min_allocator
<int>>(a2
, a2
+4)));