Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / algorithms / alg.modifying.operations / alg.partitions / partition_point.pass.cpp
blob2dc17868f80eebaf59cfb74f11090d933467da47
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 // <algorithm>
11 // template<class ForwardIterator, class Predicate>
12 // constexpr ForwardIterator // constexpr after C++17
13 // partition_point(ForwardIterator first, ForwardIterator last, Predicate pred);
15 #include <algorithm>
16 #include <cassert>
18 #include "test_macros.h"
19 #include "test_iterators.h"
21 struct is_odd
23 TEST_CONSTEXPR bool operator()(const int& i) const {return i & 1;}
27 #if TEST_STD_VER > 17
28 TEST_CONSTEXPR bool test_constexpr() {
29 int ia[] = {1, 3, 5, 2, 4, 6};
30 int ib[] = {1, 2, 3, 4, 5, 6};
31 return (std::partition_point(std::begin(ia), std::end(ia), is_odd()) == ia+3)
32 && (std::partition_point(std::begin(ib), std::end(ib), is_odd()) == ib+1)
35 #endif
38 int main(int, char**)
41 const int ia[] = {2, 4, 6, 8, 10};
42 assert(std::partition_point(forward_iterator<const int*>(std::begin(ia)),
43 forward_iterator<const int*>(std::end(ia)),
44 is_odd()) == forward_iterator<const int*>(ia));
47 const int ia[] = {1, 2, 4, 6, 8};
48 assert(std::partition_point(forward_iterator<const int*>(std::begin(ia)),
49 forward_iterator<const int*>(std::end(ia)),
50 is_odd()) == forward_iterator<const int*>(ia + 1));
53 const int ia[] = {1, 3, 2, 4, 6};
54 assert(std::partition_point(forward_iterator<const int*>(std::begin(ia)),
55 forward_iterator<const int*>(std::end(ia)),
56 is_odd()) == forward_iterator<const int*>(ia + 2));
59 const int ia[] = {1, 3, 5, 2, 4, 6};
60 assert(std::partition_point(forward_iterator<const int*>(std::begin(ia)),
61 forward_iterator<const int*>(std::end(ia)),
62 is_odd()) == forward_iterator<const int*>(ia + 3));
65 const int ia[] = {1, 3, 5, 7, 2, 4};
66 assert(std::partition_point(forward_iterator<const int*>(std::begin(ia)),
67 forward_iterator<const int*>(std::end(ia)),
68 is_odd()) == forward_iterator<const int*>(ia + 4));
71 const int ia[] = {1, 3, 5, 7, 9, 2};
72 assert(std::partition_point(forward_iterator<const int*>(std::begin(ia)),
73 forward_iterator<const int*>(std::end(ia)),
74 is_odd()) == forward_iterator<const int*>(ia + 5));
77 const int ia[] = {1, 3, 5, 7, 9, 11};
78 assert(std::partition_point(forward_iterator<const int*>(std::begin(ia)),
79 forward_iterator<const int*>(std::end(ia)),
80 is_odd()) == forward_iterator<const int*>(ia + 6));
83 const int ia[] = {1, 3, 5, 2, 4, 6, 7};
84 assert(std::partition_point(forward_iterator<const int*>(std::begin(ia)),
85 forward_iterator<const int*>(std::begin(ia)),
86 is_odd()) == forward_iterator<const int*>(ia));
89 #if TEST_STD_VER > 17
90 static_assert(test_constexpr());
91 #endif
93 return 0;