1 //===----------------------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // <algorithm>
11
12 // template<class ForwardIterator, class Predicate>
13 // ForwardIterator
14 // partition_point(ForwardIterator first, ForwardIterator last, Predicate pred);
15
16 #include <algorithm>
17 #include <cassert>
18
19 #include "test_iterators.h"
20
21 struct is_odd
22 {
operator ()is_odd23 bool operator()(const int& i) const {return i & 1;}
24 };
25
main()26 int main()
27 {
28 {
29 const int ia[] = {2, 4, 6, 8, 10};
30 assert(std::partition_point(forward_iterator<const int*>(std::begin(ia)),
31 forward_iterator<const int*>(std::end(ia)),
32 is_odd()) == forward_iterator<const int*>(ia));
33 }
34 {
35 const int ia[] = {1, 2, 4, 6, 8};
36 assert(std::partition_point(forward_iterator<const int*>(std::begin(ia)),
37 forward_iterator<const int*>(std::end(ia)),
38 is_odd()) == forward_iterator<const int*>(ia + 1));
39 }
40 {
41 const int ia[] = {1, 3, 2, 4, 6};
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 + 2));
45 }
46 {
47 const int ia[] = {1, 3, 5, 2, 4, 6};
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 + 3));
51 }
52 {
53 const int ia[] = {1, 3, 5, 7, 2, 4};
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 + 4));
57 }
58 {
59 const int ia[] = {1, 3, 5, 7, 9, 2};
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 + 5));
63 }
64 {
65 const int ia[] = {1, 3, 5, 7, 9, 11};
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 + 6));
69 }
70 {
71 const int ia[] = {1, 3, 5, 2, 4, 6, 7};
72 assert(std::partition_point(forward_iterator<const int*>(std::begin(ia)),
73 forward_iterator<const int*>(std::begin(ia)),
74 is_odd()) == forward_iterator<const int*>(ia));
75 }
76 }
77