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 InputIterator, class Predicate>
12 // constexpr bool // constexpr after C++17
13 // is_partitioned(InputIterator first, InputIterator last, Predicate pred);
20 #include "test_macros.h"
21 #include "test_iterators.h"
22 #include "counting_predicates.h"
25 TEST_CONSTEXPR
bool operator()(const int &i
) const { return i
& 1; }
29 TEST_CONSTEXPR
bool test_constexpr() {
30 int ia
[] = {1, 3, 5, 2, 4, 6};
31 int ib
[] = {1, 2, 3, 4, 5, 6};
32 return std::is_partitioned(std::begin(ia
), std::end(ia
), is_odd())
33 && !std::is_partitioned(std::begin(ib
), std::end(ib
), is_odd());
38 int main(int, char**) {
40 const int ia
[] = {1, 2, 3, 4, 5, 6};
41 unary_counting_predicate
<is_odd
, int> pred((is_odd()));
42 assert(!std::is_partitioned(cpp17_input_iterator
<const int *>(std::begin(ia
)),
43 cpp17_input_iterator
<const int *>(std::end(ia
)),
45 assert(static_cast<std::ptrdiff_t>(pred
.count()) <=
46 std::distance(std::begin(ia
), std::end(ia
)));
49 const int ia
[] = {1, 3, 5, 2, 4, 6};
50 unary_counting_predicate
<is_odd
, int> pred((is_odd()));
51 assert(std::is_partitioned(cpp17_input_iterator
<const int *>(std::begin(ia
)),
52 cpp17_input_iterator
<const int *>(std::end(ia
)),
54 assert(static_cast<std::ptrdiff_t>(pred
.count()) <=
55 std::distance(std::begin(ia
), std::end(ia
)));
58 const int ia
[] = {2, 4, 6, 1, 3, 5};
59 unary_counting_predicate
<is_odd
, int> pred((is_odd()));
60 assert(!std::is_partitioned(cpp17_input_iterator
<const int *>(std::begin(ia
)),
61 cpp17_input_iterator
<const int *>(std::end(ia
)),
63 assert(static_cast<std::ptrdiff_t>(pred
.count()) <=
64 std::distance(std::begin(ia
), std::end(ia
)));
67 const int ia
[] = {1, 3, 5, 2, 4, 6, 7};
68 unary_counting_predicate
<is_odd
, int> pred((is_odd()));
69 assert(!std::is_partitioned(cpp17_input_iterator
<const int *>(std::begin(ia
)),
70 cpp17_input_iterator
<const int *>(std::end(ia
)),
72 assert(static_cast<std::ptrdiff_t>(pred
.count()) <=
73 std::distance(std::begin(ia
), std::end(ia
)));
76 const int ia
[] = {1, 3, 5, 2, 4, 6, 7};
77 unary_counting_predicate
<is_odd
, int> pred((is_odd()));
78 assert(std::is_partitioned(cpp17_input_iterator
<const int *>(std::begin(ia
)),
79 cpp17_input_iterator
<const int *>(std::begin(ia
)),
81 assert(static_cast<std::ptrdiff_t>(pred
.count()) <=
82 std::distance(std::begin(ia
), std::begin(ia
)));
85 const int ia
[] = {1, 3, 5, 7, 9, 11, 2};
86 unary_counting_predicate
<is_odd
, int> pred((is_odd()));
87 assert(std::is_partitioned(cpp17_input_iterator
<const int *>(std::begin(ia
)),
88 cpp17_input_iterator
<const int *>(std::end(ia
)),
90 assert(static_cast<std::ptrdiff_t>(pred
.count()) <=
91 std::distance(std::begin(ia
), std::end(ia
)));
95 static_assert(test_constexpr());