[PowerPC][NFC] Cleanup PPCCTRLoopsVerify pass
[llvm-project.git] / libcxx / test / std / containers / sequences / list / list.ops / unique_pred.pass.cpp
blob75f8c7b12571c46d6880a160c14ab8ca59219351
1 //===----------------------------------------------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
9 // <list>
11 // template <class BinaryPred> void unique(BinaryPred pred); // before C++20
12 // template <class BinaryPred> size_type unique(BinaryPred pred); // C++20 and later
14 #include <list>
15 #include <cassert>
17 #include "test_macros.h"
18 #include "min_allocator.h"
20 bool g(int x, int y)
22 return x == y;
25 struct PredLWG526 {
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_;}
31 int i_;
34 int main(int, char**)
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]));
41 #if TEST_STD_VER > 17
42 ASSERT_SAME_TYPE(L::size_type, decltype(c.unique(g)));
43 assert(c.unique(g) == 5);
44 #else
45 ASSERT_SAME_TYPE(void, decltype(c.unique(g)));
46 c.unique(g);
47 #endif
48 assert(c == std::list<int>(a2, a2+4));
51 { // LWG issue #526
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);
55 #if TEST_STD_VER > 17
56 assert(c.unique(std::ref(c.front())) == 3);
57 #else
58 c.unique(std::ref(c.front()));
59 #endif
60 assert(c.size() == 6);
61 for (size_t i = 0; i < c.size(); ++i)
63 assert(c.front() == a2[i]);
64 c.pop_front();
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]));
73 #if TEST_STD_VER > 17
74 assert(c.unique(g) == 5);
75 #else
76 c.unique(g);
77 #endif
78 assert((c == std::list<int, min_allocator<int>>(a2, a2+4)));
80 #endif
82 return 0;