15a83710eSEric Fiselier //===----------------------------------------------------------------------===//
25a83710eSEric Fiselier //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
65a83710eSEric Fiselier //
75a83710eSEric Fiselier //===----------------------------------------------------------------------===//
85a83710eSEric Fiselier
95a83710eSEric Fiselier // <algorithm>
105a83710eSEric Fiselier
115a83710eSEric Fiselier // template <class InputIterator, class OutputIterator1,
125a83710eSEric Fiselier // class OutputIterator2, class Predicate>
131b9a4ffdSMarshall Clow // constexpr pair<OutputIterator1, OutputIterator2> // constexpr after C++17
145a83710eSEric Fiselier // partition_copy(InputIterator first, InputIterator last,
155a83710eSEric Fiselier // OutputIterator1 out_true, OutputIterator2 out_false,
165a83710eSEric Fiselier // Predicate pred);
175a83710eSEric Fiselier
185a83710eSEric Fiselier #include <algorithm>
195a83710eSEric Fiselier #include <cassert>
205a83710eSEric Fiselier
211b9a4ffdSMarshall Clow #include "test_macros.h"
225a83710eSEric Fiselier #include "test_iterators.h"
235a83710eSEric Fiselier
245a83710eSEric Fiselier struct is_odd
255a83710eSEric Fiselier {
operator ()is_odd261b9a4ffdSMarshall Clow TEST_CONSTEXPR bool operator()(const int& i) const {return i & 1;}
275a83710eSEric Fiselier };
285a83710eSEric Fiselier
291b9a4ffdSMarshall Clow #if TEST_STD_VER > 17
test_constexpr()301b9a4ffdSMarshall Clow TEST_CONSTEXPR bool test_constexpr() {
311b9a4ffdSMarshall Clow int ia[] = {1, 3, 5, 2, 4, 6};
321b9a4ffdSMarshall Clow int r1[10] = {0};
331b9a4ffdSMarshall Clow int r2[10] = {0};
341b9a4ffdSMarshall Clow
351b9a4ffdSMarshall Clow auto p = std::partition_copy(std::begin(ia), std::end(ia),
361b9a4ffdSMarshall Clow std::begin(r1), std::begin(r2), is_odd());
371b9a4ffdSMarshall Clow
381b9a4ffdSMarshall Clow return std::all_of(std::begin(r1), p.first, is_odd())
391b9a4ffdSMarshall Clow && std::all_of(p.first, std::end(r1), [](int a){return a == 0;})
401b9a4ffdSMarshall Clow && std::none_of(std::begin(r2), p.second, is_odd())
411b9a4ffdSMarshall Clow && std::all_of(p.second, std::end(r2), [](int a){return a == 0;})
421b9a4ffdSMarshall Clow ;
431b9a4ffdSMarshall Clow }
441b9a4ffdSMarshall Clow #endif
451b9a4ffdSMarshall Clow
main(int,char **)462df59c50SJF Bastien int main(int, char**)
475a83710eSEric Fiselier {
485a83710eSEric Fiselier {
495a83710eSEric Fiselier const int ia[] = {1, 2, 3, 4, 6, 8, 5, 7};
505a83710eSEric Fiselier int r1[10] = {0};
515a83710eSEric Fiselier int r2[10] = {0};
525e97d37bSMark de Wever typedef std::pair<cpp17_output_iterator<int*>, int*> P;
53773ae441SChristopher Di Bella P p = std::partition_copy(cpp17_input_iterator<const int*>(std::begin(ia)),
54773ae441SChristopher Di Bella cpp17_input_iterator<const int*>(std::end(ia)),
555e97d37bSMark de Wever cpp17_output_iterator<int*>(r1), r2, is_odd());
56*5f26d863SMark de Wever assert(base(p.first) == r1 + 4);
575a83710eSEric Fiselier assert(r1[0] == 1);
585a83710eSEric Fiselier assert(r1[1] == 3);
595a83710eSEric Fiselier assert(r1[2] == 5);
605a83710eSEric Fiselier assert(r1[3] == 7);
615a83710eSEric Fiselier assert(p.second == r2 + 4);
625a83710eSEric Fiselier assert(r2[0] == 2);
635a83710eSEric Fiselier assert(r2[1] == 4);
645a83710eSEric Fiselier assert(r2[2] == 6);
655a83710eSEric Fiselier assert(r2[3] == 8);
665a83710eSEric Fiselier }
671b9a4ffdSMarshall Clow
681b9a4ffdSMarshall Clow #if TEST_STD_VER > 17
691b9a4ffdSMarshall Clow static_assert(test_constexpr());
701b9a4ffdSMarshall Clow #endif
712df59c50SJF Bastien
722df59c50SJF Bastien return 0;
735a83710eSEric Fiselier }
74