]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/algorithm/is_partitioned_until.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / algorithm / is_partitioned_until.hpp
CommitLineData
b32b8144
FG
1/*
2 Copyright (c) Alexander Zaitsev <zamazan4ik@gmail.by>, 2017.
3
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6*/
7
8/// \file is_partitioned_until.hpp
9/// \brief Tell if a sequence is partitioned
10/// \author Alexander Zaitsev
11
12#ifndef BOOST_ALGORITHM_IS_PARTITIONED_UNTIL_HPP
13#define BOOST_ALGORITHM_IS_PARTITIONED_UNTIL_HPP
14
15#include <boost/range/begin.hpp>
16#include <boost/range/end.hpp>
17
18namespace boost { namespace algorithm {
19
20/// \fn is_partitioned_until ( InputIterator first, InputIterator last, UnaryPredicate p )
21/// \brief Tests to see if a sequence is partitioned according to a predicate.
22/// In other words, all the items in the sequence that satisfy the predicate are at the beginning of the sequence.
23///
24/// \param first The start of the input sequence
25/// \param last One past the end of the input sequence
26/// \param p The predicate to test the values with
27///
28/// \note Returns the first iterator 'it' in the sequence [first, last) for which is_partitioned(first, it, p) is false.
29/// Returns last if the entire sequence is partitioned.
30/// Complexity: O(N).
31template <typename InputIterator, typename UnaryPredicate>
32InputIterator is_partitioned_until ( InputIterator first, InputIterator last, UnaryPredicate p )
33{
34// Run through the part that satisfy the predicate
35 for ( ; first != last; ++first )
36 if ( !p (*first))
37 break;
38// Now the part that does not satisfy the predicate
39 for ( ; first != last; ++first )
40 if ( p (*first))
41 return first;
42 return last;
43}
44
45/// \fn is_partitioned_until ( const Range &r, UnaryPredicate p )
46/// \brief Tests to see if a sequence is partitioned according to a predicate.
47/// In other words, all the items in the sequence that satisfy the predicate are at the beginning of the sequence.
48///
49/// \param r The input range
50/// \param p The predicate to test the values with
51///
52/// \note Returns the first iterator 'it' in the sequence [first, last) for which is_partitioned(first, it, p) is false.
53/// Returns last if the entire sequence is partitioned.
54/// Complexity: O(N).
55template <typename Range, typename UnaryPredicate>
56typename boost::range_iterator<const Range>::type is_partitioned_until ( const Range &r, UnaryPredicate p )
57{
58 return boost::algorithm::is_partitioned_until (boost::begin(r), boost::end(r), p);
59}
60
61}}
62
63#endif // BOOST_ALGORITHM_IS_PARTITIONED_UNTIL_HPP