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 ForwardIterator, class Predicate>
12*530c69e9SArthur O'Dwyer // constexpr ForwardIterator // constexpr after C++17
135a83710eSEric Fiselier // partition_point(ForwardIterator first, ForwardIterator last, Predicate pred);
145a83710eSEric Fiselier
155a83710eSEric Fiselier #include <algorithm>
165a83710eSEric Fiselier #include <cassert>
175a83710eSEric Fiselier
18674f9128SMarshall Clow #include "test_macros.h"
195a83710eSEric Fiselier #include "test_iterators.h"
205a83710eSEric Fiselier
215a83710eSEric Fiselier struct is_odd
225a83710eSEric Fiselier {
operator ()is_odd23674f9128SMarshall Clow TEST_CONSTEXPR bool operator()(const int& i) const {return i & 1;}
245a83710eSEric Fiselier };
255a83710eSEric Fiselier
26674f9128SMarshall Clow
27674f9128SMarshall Clow #if TEST_STD_VER > 17
test_constexpr()28404ee020SMarshall Clow TEST_CONSTEXPR bool test_constexpr() {
29674f9128SMarshall Clow int ia[] = {1, 3, 5, 2, 4, 6};
30674f9128SMarshall Clow int ib[] = {1, 2, 3, 4, 5, 6};
31674f9128SMarshall Clow return (std::partition_point(std::begin(ia), std::end(ia), is_odd()) == ia+3)
32674f9128SMarshall Clow && (std::partition_point(std::begin(ib), std::end(ib), is_odd()) == ib+1)
33674f9128SMarshall Clow ;
34674f9128SMarshall Clow }
35674f9128SMarshall Clow #endif
36674f9128SMarshall Clow
37674f9128SMarshall Clow
main(int,char **)382df59c50SJF Bastien int main(int, char**)
395a83710eSEric Fiselier {
405a83710eSEric Fiselier {
415a83710eSEric Fiselier const int ia[] = {2, 4, 6, 8, 10};
425a83710eSEric Fiselier assert(std::partition_point(forward_iterator<const int*>(std::begin(ia)),
435a83710eSEric Fiselier forward_iterator<const int*>(std::end(ia)),
445a83710eSEric Fiselier is_odd()) == forward_iterator<const int*>(ia));
455a83710eSEric Fiselier }
465a83710eSEric Fiselier {
475a83710eSEric Fiselier const int ia[] = {1, 2, 4, 6, 8};
485a83710eSEric Fiselier assert(std::partition_point(forward_iterator<const int*>(std::begin(ia)),
495a83710eSEric Fiselier forward_iterator<const int*>(std::end(ia)),
505a83710eSEric Fiselier is_odd()) == forward_iterator<const int*>(ia + 1));
515a83710eSEric Fiselier }
525a83710eSEric Fiselier {
535a83710eSEric Fiselier const int ia[] = {1, 3, 2, 4, 6};
545a83710eSEric Fiselier assert(std::partition_point(forward_iterator<const int*>(std::begin(ia)),
555a83710eSEric Fiselier forward_iterator<const int*>(std::end(ia)),
565a83710eSEric Fiselier is_odd()) == forward_iterator<const int*>(ia + 2));
575a83710eSEric Fiselier }
585a83710eSEric Fiselier {
595a83710eSEric Fiselier const int ia[] = {1, 3, 5, 2, 4, 6};
605a83710eSEric Fiselier assert(std::partition_point(forward_iterator<const int*>(std::begin(ia)),
615a83710eSEric Fiselier forward_iterator<const int*>(std::end(ia)),
625a83710eSEric Fiselier is_odd()) == forward_iterator<const int*>(ia + 3));
635a83710eSEric Fiselier }
645a83710eSEric Fiselier {
655a83710eSEric Fiselier const int ia[] = {1, 3, 5, 7, 2, 4};
665a83710eSEric Fiselier assert(std::partition_point(forward_iterator<const int*>(std::begin(ia)),
675a83710eSEric Fiselier forward_iterator<const int*>(std::end(ia)),
685a83710eSEric Fiselier is_odd()) == forward_iterator<const int*>(ia + 4));
695a83710eSEric Fiselier }
705a83710eSEric Fiselier {
715a83710eSEric Fiselier const int ia[] = {1, 3, 5, 7, 9, 2};
725a83710eSEric Fiselier assert(std::partition_point(forward_iterator<const int*>(std::begin(ia)),
735a83710eSEric Fiselier forward_iterator<const int*>(std::end(ia)),
745a83710eSEric Fiselier is_odd()) == forward_iterator<const int*>(ia + 5));
755a83710eSEric Fiselier }
765a83710eSEric Fiselier {
775a83710eSEric Fiselier const int ia[] = {1, 3, 5, 7, 9, 11};
785a83710eSEric Fiselier assert(std::partition_point(forward_iterator<const int*>(std::begin(ia)),
795a83710eSEric Fiselier forward_iterator<const int*>(std::end(ia)),
805a83710eSEric Fiselier is_odd()) == forward_iterator<const int*>(ia + 6));
815a83710eSEric Fiselier }
825a83710eSEric Fiselier {
835a83710eSEric Fiselier const int ia[] = {1, 3, 5, 2, 4, 6, 7};
845a83710eSEric Fiselier assert(std::partition_point(forward_iterator<const int*>(std::begin(ia)),
855a83710eSEric Fiselier forward_iterator<const int*>(std::begin(ia)),
865a83710eSEric Fiselier is_odd()) == forward_iterator<const int*>(ia));
875a83710eSEric Fiselier }
88674f9128SMarshall Clow
89674f9128SMarshall Clow #if TEST_STD_VER > 17
90674f9128SMarshall Clow static_assert(test_constexpr());
91674f9128SMarshall Clow #endif
922df59c50SJF Bastien
932df59c50SJF Bastien return 0;
945a83710eSEric Fiselier }
95