2013-08-08 09:54:33 +00:00
|
|
|
/*=============================================================================
|
|
|
|
Copyright (c) 2011-2013 Bolero MURAKAMI
|
|
|
|
Copyright (C) 2011 RiSK (sscrisk)
|
|
|
|
https://github.com/bolero-MURAKAMI/Sprout
|
|
|
|
|
|
|
|
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
=============================================================================*/
|
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>
|
|
|
|
|
|
|
|
namespace sprout {
|
|
|
|
|
|
|
|
namespace detail {
|
|
|
|
template<typename ForwardIterator, typename Predicate>
|
2012-10-06 04:53:07 +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(
|
2012-10-06 04:53:07 +00:00
|
|
|
sprout::next(mid), last, pred,
|
2013-01-10 17:55:19 +00:00
|
|
|
sprout::next(mid, 1 + (sprout::distance(mid, last) - 1) / 2)
|
2012-04-03 12:58:23 +00:00
|
|
|
)
|
|
|
|
: sprout::detail::partition_point_impl(
|
2012-10-06 04:53:07 +00:00
|
|
|
first, mid, pred,
|
2013-01-03 08:01:50 +00:00
|
|
|
sprout::next(first, sprout::distance(first, mid) / 2)
|
2012-04-03 12:58:23 +00:00
|
|
|
)
|
2012-04-01 13:15:09 +00:00
|
|
|
;
|
|
|
|
}
|
|
|
|
} // namespace detail
|
|
|
|
|
|
|
|
// 25.3.13 Partitions
|
2012-12-15 08:41:20 +00:00
|
|
|
//
|
|
|
|
// recursion depth:
|
2013-01-10 17:55:19 +00:00
|
|
|
// O(log N)
|
2012-12-15 08:41:20 +00:00
|
|
|
//
|
2012-04-01 13:15:09 +00:00
|
|
|
template<typename ForwardIterator, typename Predicate>
|
2012-10-06 04:53:07 +00:00
|
|
|
inline SPROUT_CONSTEXPR ForwardIterator
|
|
|
|
partition_point(ForwardIterator first, ForwardIterator last, Predicate pred) {
|
|
|
|
return sprout::detail::partition_point_impl(
|
|
|
|
first, last, pred,
|
2013-01-03 08:01:50 +00:00
|
|
|
sprout::next(first, sprout::distance(first, last) / 2)
|
2012-10-06 04:53:07 +00:00
|
|
|
);
|
2012-04-01 13:15:09 +00:00
|
|
|
}
|
|
|
|
} // namespace sprout
|
|
|
|
|
|
|
|
#endif // #ifndef SPROUT_ALGORITHM_PARTITION_POINT_HPP
|