fix rexursion depth: is_pertitioned, partition_point, is_sorted, is_sorted_until

This commit is contained in:
bolero-MURAKAMI 2012-12-15 17:41:20 +09:00
parent d6914ddd72
commit eea1c2bbc1
12 changed files with 410 additions and 50 deletions

View file

@ -2,28 +2,20 @@
#define SPROUT_ALGORITHM_IS_PARTITIONED_HPP
#include <sprout/config.hpp>
#include <sprout/iterator/operation.hpp>
#include <sprout/algorithm/none_of.hpp>
#include <sprout/algorithm/find_if_not.hpp>
namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk)
namespace detail {
template<typename InputIterator, typename Predicate>
inline SPROUT_CONSTEXPR bool
is_partitioned_impl(InputIterator first, InputIterator last, Predicate pred, bool cond = true) {
return first == last ? true
: cond ? sprout::detail::is_partitioned_impl(sprout::next(first), last, pred, pred(*first))
: pred(*first) ? false
: sprout::detail::is_partitioned_impl(sprout::next(first), last, pred, false)
;
}
} // namespace detail
// 25.3.13 Partitions
//
// recursion depth:
// [first, last) is RandomAccessIterator -> O(log N)
// otherwise -> O(N)
//
template<typename InputIterator, typename Predicate>
inline SPROUT_CONSTEXPR bool
is_partitioned(InputIterator first, InputIterator last, Predicate pred) {
return sprout::detail::is_partitioned_impl(first, last, pred);
return sprout::none_of(sprout::find_if_not(first, last, pred), last, pred);
}
} // namespace sprout