File indexing completed on 2025-01-18 09:28:23
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef BOOST_ALGORITHM_PARTITION_POINT_HPP
0013 #define BOOST_ALGORITHM_PARTITION_POINT_HPP
0014
0015 #include <iterator> // for std::distance, advance
0016
0017 #include <boost/config.hpp>
0018 #include <boost/range/begin.hpp>
0019 #include <boost/range/end.hpp>
0020
0021 namespace boost { namespace algorithm {
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031 template <typename ForwardIterator, typename Predicate>
0032 ForwardIterator partition_point ( ForwardIterator first, ForwardIterator last, Predicate p )
0033 {
0034 std::size_t dist = std::distance ( first, last );
0035 while ( first != last ) {
0036 std::size_t d2 = dist / 2;
0037 ForwardIterator ret_val = first;
0038 std::advance (ret_val, d2);
0039 if (p (*ret_val)) {
0040 first = ++ret_val;
0041 dist -= d2 + 1;
0042 }
0043 else {
0044 last = ret_val;
0045 dist = d2;
0046 }
0047 }
0048 return first;
0049 }
0050
0051
0052
0053
0054
0055
0056
0057 template <typename Range, typename Predicate>
0058 typename boost::range_iterator<Range>::type partition_point ( Range &r, Predicate p )
0059 {
0060 return boost::algorithm::partition_point (boost::begin(r), boost::end(r), p);
0061 }
0062
0063
0064 }}
0065
0066 #endif