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 InputIterator, class Predicate> 13 // bool 14 // is_partitioned(InputIterator first, InputIterator last, Predicate pred); 15 16 #include <algorithm> 17 #include <functional> 18 #include <cstddef> 19 #include <cassert> 20 21 #include "test_iterators.h" 22 #include "counting_predicates.hpp" 23 24 struct is_odd { 25 bool operator()(const int &i) const { return i & 1; } 26 }; 27 28 int main() { 29 { 30 const int ia[] = {1, 2, 3, 4, 5, 6}; 31 unary_counting_predicate<is_odd, int> pred((is_odd())); 32 assert(!std::is_partitioned(input_iterator<const int *>(std::begin(ia)), 33 input_iterator<const int *>(std::end(ia)), 34 std::ref(pred))); 35 assert(static_cast<std::ptrdiff_t>(pred.count()) <= 36 std::distance(std::begin(ia), std::end(ia))); 37 } 38 { 39 const int ia[] = {1, 3, 5, 2, 4, 6}; 40 unary_counting_predicate<is_odd, int> pred((is_odd())); 41 assert(std::is_partitioned(input_iterator<const int *>(std::begin(ia)), 42 input_iterator<const int *>(std::end(ia)), 43 std::ref(pred))); 44 assert(static_cast<std::ptrdiff_t>(pred.count()) <= 45 std::distance(std::begin(ia), std::end(ia))); 46 } 47 { 48 const int ia[] = {2, 4, 6, 1, 3, 5}; 49 unary_counting_predicate<is_odd, int> pred((is_odd())); 50 assert(!std::is_partitioned(input_iterator<const int *>(std::begin(ia)), 51 input_iterator<const int *>(std::end(ia)), 52 std::ref(pred))); 53 assert(static_cast<std::ptrdiff_t>(pred.count()) <= 54 std::distance(std::begin(ia), std::end(ia))); 55 } 56 { 57 const int ia[] = {1, 3, 5, 2, 4, 6, 7}; 58 unary_counting_predicate<is_odd, int> pred((is_odd())); 59 assert(!std::is_partitioned(input_iterator<const int *>(std::begin(ia)), 60 input_iterator<const int *>(std::end(ia)), 61 std::ref(pred))); 62 assert(static_cast<std::ptrdiff_t>(pred.count()) <= 63 std::distance(std::begin(ia), std::end(ia))); 64 } 65 { 66 const int ia[] = {1, 3, 5, 2, 4, 6, 7}; 67 unary_counting_predicate<is_odd, int> pred((is_odd())); 68 assert(std::is_partitioned(input_iterator<const int *>(std::begin(ia)), 69 input_iterator<const int *>(std::begin(ia)), 70 std::ref(pred))); 71 assert(static_cast<std::ptrdiff_t>(pred.count()) <= 72 std::distance(std::begin(ia), std::begin(ia))); 73 } 74 { 75 const int ia[] = {1, 3, 5, 7, 9, 11, 2}; 76 unary_counting_predicate<is_odd, int> pred((is_odd())); 77 assert(std::is_partitioned(input_iterator<const int *>(std::begin(ia)), 78 input_iterator<const int *>(std::end(ia)), 79 std::ref(pred))); 80 assert(static_cast<std::ptrdiff_t>(pred.count()) <= 81 std::distance(std::begin(ia), std::end(ia))); 82 } 83 } 84