2012-04-01 13:15:09 +00:00
|
|
|
#ifndef SPROUT_ALGORITHM_PARTITION_POINT_HPP
|
|
|
|
#define SPROUT_ALGORITHM_PARTITION_POINT_HPP
|
|
|
|
|
|
|
|
#include <sprout/config.hpp>
|
|
|
|
#include <sprout/iterator/operation.hpp>
|
|
|
|
#include HDR_ITERATOR_SSCRISK_CEL_OR_SPROUT
|
|
|
|
|
|
|
|
namespace sprout {
|
|
|
|
// Copyright (C) 2011 RiSK (sscrisk)
|
|
|
|
|
|
|
|
namespace detail {
|
|
|
|
template<typename ForwardIterator, typename Predicate>
|
2012-04-04 13:23:41 +00:00
|
|
|
inline SPROUT_CONSTEXPR ForwardIterator partition_point_impl(ForwardIterator first, ForwardIterator last, Predicate pred, ForwardIterator mid) {
|
2012-04-01 13:15:09 +00:00
|
|
|
return mid == last ? mid
|
2012-04-03 12:58:23 +00:00
|
|
|
: pred(*mid) ? sprout::detail::partition_point_impl(
|
|
|
|
sprout::next(mid),
|
|
|
|
last,
|
|
|
|
pred,
|
|
|
|
sprout::next(mid, 1 + NS_SSCRISK_CEL_OR_SPROUT::distance(sprout::next(mid), last) / 2)
|
|
|
|
)
|
|
|
|
: sprout::detail::partition_point_impl(
|
|
|
|
first,
|
|
|
|
mid,
|
|
|
|
pred,
|
|
|
|
sprout::next(first, NS_SSCRISK_CEL_OR_SPROUT::distance(first, mid) / 2)
|
|
|
|
)
|
2012-04-01 13:15:09 +00:00
|
|
|
;
|
|
|
|
}
|
|
|
|
} // namespace detail
|
|
|
|
|
|
|
|
// 25.3.13 Partitions
|
|
|
|
template<typename ForwardIterator, typename Predicate>
|
2012-04-04 13:23:41 +00:00
|
|
|
inline SPROUT_CONSTEXPR ForwardIterator partition_point(ForwardIterator first, ForwardIterator last, Predicate pred) {
|
2012-04-03 12:58:23 +00:00
|
|
|
return sprout::detail::partition_point_impl(first, last, pred, sprout::next(first, NS_SSCRISK_CEL_OR_SPROUT::distance(first, last) / 2));
|
2012-04-01 13:15:09 +00:00
|
|
|
}
|
|
|
|
} // namespace sprout
|
|
|
|
|
|
|
|
#endif // #ifndef SPROUT_ALGORITHM_PARTITION_POINT_HPP
|