Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:28:23

0001 /* 
0002    Copyright (c) Marshall Clow 2011-2012.
0003 
0004    Distributed under the Boost Software License, Version 1.0. (See accompanying
0005    file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 */
0007 
0008 /// \file  partition_point.hpp
0009 /// \brief Find the partition point in a sequence
0010 /// \author Marshall Clow
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 /// \fn partition_point ( ForwardIterator first, ForwardIterator last, Predicate p )
0024 /// \brief Given a partitioned range, returns the partition point, i.e, the first element 
0025 ///     that does not satisfy p
0026 /// 
0027 /// \param first    The start of the input sequence
0028 /// \param last     One past the end of the input sequence
0029 /// \param p        The predicate to test the values with
0030 /// \note           This function is part of the C++2011 standard library.
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 /// \fn partition_point ( Range &r, Predicate p )
0052 /// \brief Given a partitioned range, returns the partition point
0053 /// 
0054 /// \param r        The input range
0055 /// \param p        The predicate to test the values with
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  // BOOST_ALGORITHM_PARTITION_POINT_HPP