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//===----------------------------------------------------------------------===//
8
9// <algorithm>
10
11// template <class InputIterator, class OutputIterator1,
12// class OutputIterator2, class Predicate>
13// constexpr pair<OutputIterator1, OutputIterator2> // constexpr after C++17
14// partition_copy(InputIterator first, InputIterator last,
15// OutputIterator1 out_true, OutputIterator2 out_false,
16// Predicate pred);
17
18#include <algorithm>
19#include <cassert>
20
21#include "test_macros.h"
22#include "test_iterators.h"
23
24struct is_odd
25{
26 TEST_CONSTEXPR bool operator()(const int& i) const {return i & 1;}
27};
28
29#if TEST_STD_VER > 17
30TEST_CONSTEXPR bool test_constexpr() {
31 int ia[] = {1, 3, 5, 2, 4, 6};
32 int r1[10] = {0};
33 int r2[10] = {0};
34
35 auto p = std::partition_copy(std::begin(ia), std::end(ia),
36 std::begin(r1), std::begin(r2), is_odd());
37
38 return std::all_of(std::begin(r1), p.first, is_odd())
39 && std::all_of(p.first, std::end(r1), [](int a){return a == 0;})
40 && std::none_of(std::begin(r2), p.second, is_odd())
41 && std::all_of(p.second, std::end(r2), [](int a){return a == 0;})
42 ;
43 }
44#endif
45
46int main(int, char**)
47{
48 {
49 const int ia[] = {1, 2, 3, 4, 6, 8, 5, 7};
50 int r1[10] = {0};
51 int r2[10] = {0};
52 typedef std::pair<cpp17_output_iterator<int*>, int*> P;
53 P p = std::partition_copy(cpp17_input_iterator<const int*>(std::begin(arr: ia)),
54 cpp17_input_iterator<const int*>(std::end(arr: ia)),
55 cpp17_output_iterator<int*>(r1), r2, is_odd());
56 assert(base(p.first) == r1 + 4);
57 assert(r1[0] == 1);
58 assert(r1[1] == 3);
59 assert(r1[2] == 5);
60 assert(r1[3] == 7);
61 assert(p.second == r2 + 4);
62 assert(r2[0] == 2);
63 assert(r2[1] == 4);
64 assert(r2[2] == 6);
65 assert(r2[3] == 8);
66 }
67
68#if TEST_STD_VER > 17
69 static_assert(test_constexpr());
70#endif
71
72 return 0;
73}
74

source code of libcxx/test/std/algorithms/alg.modifying.operations/alg.partitions/partition_copy.pass.cpp