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 // constpexr ForwardIterator // constexpr after C++17 14 // partition_point(ForwardIterator first, ForwardIterator last, Predicate pred); 15 16 #include <algorithm> 17 #include <cassert> 18 19 #include "test_macros.h" 20 #include "test_iterators.h" 21 22 struct is_odd 23 { 24 TEST_CONSTEXPR bool operator()(const int& i) const {return i & 1;} 25 }; 26 27 28 #if TEST_STD_VER > 17 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::partition_point(std::begin(ia), std::end(ia), is_odd()) == ia+3) 33 && (std::partition_point(std::begin(ib), std::end(ib), is_odd()) == ib+1) 34 ; 35 } 36 #endif 37 38 39 int main() 40 { 41 { 42 const int ia[] = {2, 4, 6, 8, 10}; 43 assert(std::partition_point(forward_iterator<const int*>(std::begin(ia)), 44 forward_iterator<const int*>(std::end(ia)), 45 is_odd()) == forward_iterator<const int*>(ia)); 46 } 47 { 48 const int ia[] = {1, 2, 4, 6, 8}; 49 assert(std::partition_point(forward_iterator<const int*>(std::begin(ia)), 50 forward_iterator<const int*>(std::end(ia)), 51 is_odd()) == forward_iterator<const int*>(ia + 1)); 52 } 53 { 54 const int ia[] = {1, 3, 2, 4, 6}; 55 assert(std::partition_point(forward_iterator<const int*>(std::begin(ia)), 56 forward_iterator<const int*>(std::end(ia)), 57 is_odd()) == forward_iterator<const int*>(ia + 2)); 58 } 59 { 60 const int ia[] = {1, 3, 5, 2, 4, 6}; 61 assert(std::partition_point(forward_iterator<const int*>(std::begin(ia)), 62 forward_iterator<const int*>(std::end(ia)), 63 is_odd()) == forward_iterator<const int*>(ia + 3)); 64 } 65 { 66 const int ia[] = {1, 3, 5, 7, 2, 4}; 67 assert(std::partition_point(forward_iterator<const int*>(std::begin(ia)), 68 forward_iterator<const int*>(std::end(ia)), 69 is_odd()) == forward_iterator<const int*>(ia + 4)); 70 } 71 { 72 const int ia[] = {1, 3, 5, 7, 9, 2}; 73 assert(std::partition_point(forward_iterator<const int*>(std::begin(ia)), 74 forward_iterator<const int*>(std::end(ia)), 75 is_odd()) == forward_iterator<const int*>(ia + 5)); 76 } 77 { 78 const int ia[] = {1, 3, 5, 7, 9, 11}; 79 assert(std::partition_point(forward_iterator<const int*>(std::begin(ia)), 80 forward_iterator<const int*>(std::end(ia)), 81 is_odd()) == forward_iterator<const int*>(ia + 6)); 82 } 83 { 84 const int ia[] = {1, 3, 5, 2, 4, 6, 7}; 85 assert(std::partition_point(forward_iterator<const int*>(std::begin(ia)), 86 forward_iterator<const int*>(std::begin(ia)), 87 is_odd()) == forward_iterator<const int*>(ia)); 88 } 89 90 #if TEST_STD_VER > 17 91 static_assert(test_constexpr()); 92 #endif 93 } 94