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 <cassert> 18 19 #include "test_iterators.h" 20 #include "counting_predicates.hpp" 21 22 struct is_odd 23 { 24 bool operator()(const int& i) const {return i & 1;} 25 }; 26 27 int main() 28 { 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(pred.count() <= std::distance(std::begin(ia), std::end(ia))); 36 } 37 { 38 const int ia[] = {1, 3, 5, 2, 4, 6}; 39 unary_counting_predicate<is_odd, int> pred((is_odd())); 40 assert( std::is_partitioned(input_iterator<const int*>(std::begin(ia)), 41 input_iterator<const int*>(std::end(ia)), 42 std::ref(pred))); 43 assert(pred.count() <= std::distance(std::begin(ia), std::end(ia))); 44 } 45 { 46 const int ia[] = {2, 4, 6, 1, 3, 5}; 47 unary_counting_predicate<is_odd, int> pred((is_odd())); 48 assert(!std::is_partitioned(input_iterator<const int*>(std::begin(ia)), 49 input_iterator<const int*>(std::end(ia)), 50 std::ref(pred))); 51 assert(pred.count() <= std::distance(std::begin(ia), std::end(ia))); 52 } 53 { 54 const int ia[] = {1, 3, 5, 2, 4, 6, 7}; 55 unary_counting_predicate<is_odd, int> pred((is_odd())); 56 assert(!std::is_partitioned(input_iterator<const int*>(std::begin(ia)), 57 input_iterator<const int*>(std::end(ia)), 58 std::ref(pred))); 59 assert(pred.count() <= std::distance(std::begin(ia), std::end(ia))); 60 } 61 { 62 const int ia[] = {1, 3, 5, 2, 4, 6, 7}; 63 unary_counting_predicate<is_odd, int> pred((is_odd())); 64 assert( std::is_partitioned(input_iterator<const int*>(std::begin(ia)), 65 input_iterator<const int*>(std::begin(ia)), 66 std::ref(pred))); 67 assert(pred.count() <= std::distance(std::begin(ia), std::begin(ia))); 68 } 69 { 70 const int ia[] = {1, 3, 5, 7, 9, 11, 2}; 71 unary_counting_predicate<is_odd, int> pred((is_odd())); 72 assert( std::is_partitioned(input_iterator<const int*>(std::begin(ia)), 73 input_iterator<const int*>(std::end(ia)), 74 std::ref(pred))); 75 assert(pred.count() <= std::distance(std::begin(ia), std::end(ia))); 76 } 77 } 78