123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- #ifndef BOOST_ALGORITHM_PARTITION_POINT_HPP
- #define BOOST_ALGORITHM_PARTITION_POINT_HPP
- #include <iterator> // for std::distance, advance
- #include <boost/config.hpp>
- #include <boost/range/begin.hpp>
- #include <boost/range/end.hpp>
- namespace boost { namespace algorithm {
- template <typename ForwardIterator, typename Predicate>
- ForwardIterator partition_point ( ForwardIterator first, ForwardIterator last, Predicate p )
- {
- std::size_t dist = std::distance ( first, last );
- while ( first != last ) {
- std::size_t d2 = dist / 2;
- ForwardIterator ret_val = first;
- std::advance (ret_val, d2);
- if (p (*ret_val)) {
- first = ++ret_val;
- dist -= d2 + 1;
- }
- else {
- last = ret_val;
- dist = d2;
- }
- }
- return first;
- }
- template <typename Range, typename Predicate>
- typename boost::range_iterator<Range>::type partition_point ( Range &r, Predicate p )
- {
- return boost::algorithm::partition_point (boost::begin(r), boost::end(r), p);
- }
- }}
- #endif
|