mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2025-07-12 14:54:10 +00:00
fix rexursion depth: is_pertitioned, partition_point, is_sorted, is_sorted_until
This commit is contained in:
parent
d6914ddd72
commit
eea1c2bbc1
12 changed files with 410 additions and 50 deletions
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue