2010-05-12 03:42:16 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2010-05-12 05:36:01 +08:00
|
|
|
// The LLVM Compiler Infrastructure
|
2010-05-12 03:42:16 +08:00
|
|
|
//
|
2010-11-17 06:09:02 +08:00
|
|
|
// This file is dual licensed under the MIT and the University of Illinois Open
|
|
|
|
// Source Licenses. See LICENSE.TXT for details.
|
2010-05-12 03:42:16 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
// <algorithm>
|
|
|
|
|
|
|
|
// template <class InputIterator, class Predicate>
|
|
|
|
// bool
|
|
|
|
// is_partitioned(InputIterator first, InputIterator last, Predicate pred);
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <cassert>
|
|
|
|
|
2013-01-05 11:21:01 +08:00
|
|
|
#include "test_iterators.h"
|
2015-02-03 02:16:35 +08:00
|
|
|
#include "counting_predicates.hpp"
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
struct is_odd
|
|
|
|
{
|
|
|
|
bool operator()(const int& i) const {return i & 1;}
|
|
|
|
};
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
const int ia[] = {1, 2, 3, 4, 5, 6};
|
2015-02-03 02:16:35 +08:00
|
|
|
unary_counting_predicate<is_odd, int> pred((is_odd()));
|
2010-05-12 03:42:16 +08:00
|
|
|
assert(!std::is_partitioned(input_iterator<const int*>(std::begin(ia)),
|
|
|
|
input_iterator<const int*>(std::end(ia)),
|
2015-02-03 02:16:35 +08:00
|
|
|
std::ref(pred)));
|
|
|
|
assert(pred.count() <= std::distance(std::begin(ia), std::end(ia)));
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
{
|
|
|
|
const int ia[] = {1, 3, 5, 2, 4, 6};
|
2015-02-03 02:16:35 +08:00
|
|
|
unary_counting_predicate<is_odd, int> pred((is_odd()));
|
2010-05-12 03:42:16 +08:00
|
|
|
assert( std::is_partitioned(input_iterator<const int*>(std::begin(ia)),
|
|
|
|
input_iterator<const int*>(std::end(ia)),
|
2015-02-03 02:16:35 +08:00
|
|
|
std::ref(pred)));
|
|
|
|
assert(pred.count() <= std::distance(std::begin(ia), std::end(ia)));
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
{
|
|
|
|
const int ia[] = {2, 4, 6, 1, 3, 5};
|
2015-02-03 02:16:35 +08:00
|
|
|
unary_counting_predicate<is_odd, int> pred((is_odd()));
|
2010-05-12 03:42:16 +08:00
|
|
|
assert(!std::is_partitioned(input_iterator<const int*>(std::begin(ia)),
|
|
|
|
input_iterator<const int*>(std::end(ia)),
|
2015-02-03 02:16:35 +08:00
|
|
|
std::ref(pred)));
|
|
|
|
assert(pred.count() <= std::distance(std::begin(ia), std::end(ia)));
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
{
|
|
|
|
const int ia[] = {1, 3, 5, 2, 4, 6, 7};
|
2015-02-03 02:16:35 +08:00
|
|
|
unary_counting_predicate<is_odd, int> pred((is_odd()));
|
2010-05-12 03:42:16 +08:00
|
|
|
assert(!std::is_partitioned(input_iterator<const int*>(std::begin(ia)),
|
|
|
|
input_iterator<const int*>(std::end(ia)),
|
2015-02-03 02:16:35 +08:00
|
|
|
std::ref(pred)));
|
|
|
|
assert(pred.count() <= std::distance(std::begin(ia), std::end(ia)));
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
{
|
|
|
|
const int ia[] = {1, 3, 5, 2, 4, 6, 7};
|
2015-02-03 02:16:35 +08:00
|
|
|
unary_counting_predicate<is_odd, int> pred((is_odd()));
|
2010-05-12 03:42:16 +08:00
|
|
|
assert( std::is_partitioned(input_iterator<const int*>(std::begin(ia)),
|
|
|
|
input_iterator<const int*>(std::begin(ia)),
|
2015-02-03 02:16:35 +08:00
|
|
|
std::ref(pred)));
|
|
|
|
assert(pred.count() <= std::distance(std::begin(ia), std::begin(ia)));
|
|
|
|
}
|
|
|
|
{
|
|
|
|
const int ia[] = {1, 3, 5, 7, 9, 11, 2};
|
|
|
|
unary_counting_predicate<is_odd, int> pred((is_odd()));
|
|
|
|
assert( std::is_partitioned(input_iterator<const int*>(std::begin(ia)),
|
|
|
|
input_iterator<const int*>(std::end(ia)),
|
|
|
|
std::ref(pred)));
|
|
|
|
assert(pred.count() <= std::distance(std::begin(ia), std::end(ia)));
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
}
|