Chris@16: /* Chris@16: Copyright (c) Marshall Clow 2011-2012. Chris@16: Chris@16: Distributed under the Boost Software License, Version 1.0. (See accompanying Chris@16: file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: */ Chris@16: Chris@16: /// \file partition_point.hpp Chris@16: /// \brief Find the partition point in a sequence Chris@16: /// \author Marshall Clow Chris@16: Chris@16: #ifndef BOOST_ALGORITHM_PARTITION_POINT_HPP Chris@16: #define BOOST_ALGORITHM_PARTITION_POINT_HPP Chris@16: Chris@16: #include // for std::partition_point, if available Chris@16: Chris@16: #include Chris@16: #include Chris@16: Chris@16: namespace boost { namespace algorithm { Chris@16: Chris@16: /// \fn partition_point ( ForwardIterator first, ForwardIterator last, Predicate p ) Chris@16: /// \brief Given a partitioned range, returns the partition point, i.e, the first element Chris@16: /// that does not satisfy p Chris@16: /// Chris@16: /// \param first The start of the input sequence Chris@16: /// \param last One past the end of the input sequence Chris@16: /// \param p The predicate to test the values with Chris@16: /// \note This function is part of the C++2011 standard library. Chris@16: /// We will use the standard one if it is available, Chris@16: /// otherwise we have our own implementation. Chris@16: template Chris@16: ForwardIterator partition_point ( ForwardIterator first, ForwardIterator last, Predicate p ) Chris@16: { Chris@16: std::size_t dist = std::distance ( first, last ); Chris@16: while ( first != last ) { Chris@16: std::size_t d2 = dist / 2; Chris@16: ForwardIterator ret_val = first; Chris@16: std::advance (ret_val, d2); Chris@16: if (p (*ret_val)) { Chris@16: first = ++ret_val; Chris@16: dist -= d2 + 1; Chris@16: } Chris@16: else { Chris@16: last = ret_val; Chris@16: dist = d2; Chris@16: } Chris@16: } Chris@16: return first; Chris@16: } Chris@16: Chris@16: /// \fn partition_point ( Range &r, Predicate p ) Chris@16: /// \brief Given a partitioned range, returns the partition point Chris@16: /// Chris@16: /// \param r The input range Chris@16: /// \param p The predicate to test the values with Chris@16: /// Chris@16: template Chris@101: typename boost::range_iterator::type partition_point ( Range &r, Predicate p ) Chris@16: { Chris@16: return boost::algorithm::partition_point (boost::begin(r), boost::end(r), p); Chris@16: } Chris@16: Chris@16: Chris@16: }} Chris@16: Chris@16: #endif // BOOST_ALGORITHM_PARTITION_POINT_HPP