Back to home page

EIC code displayed by LXR

 
 

    


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

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  is_partitioned.hpp
0009 /// \brief Tell if a sequence is partitioned
0010 /// \author Marshall Clow
0011 
0012 #ifndef BOOST_ALGORITHM_IS_PARTITIONED_HPP
0013 #define BOOST_ALGORITHM_IS_PARTITIONED_HPP
0014 
0015 #include <boost/config.hpp>
0016 #include <boost/range/begin.hpp>
0017 #include <boost/range/end.hpp>
0018 
0019 namespace boost { namespace algorithm {
0020 
0021 /// \fn is_partitioned ( InputIterator first, InputIterator last, UnaryPredicate p )
0022 /// \brief Tests to see if a sequence is partitioned according to a predicate. 
0023 ///    In other words, all the items in the sequence that satisfy the predicate are at the beginning of the sequence.
0024 /// 
0025 /// \param first    The start of the input sequence
0026 /// \param last     One past the end of the input sequence
0027 /// \param p        The predicate to test the values with
0028 /// \note           This function is part of the C++2011 standard library.
0029 template <typename InputIterator, typename UnaryPredicate>
0030 BOOST_CXX14_CONSTEXPR bool is_partitioned ( InputIterator first, InputIterator last, UnaryPredicate p )
0031 {
0032 //  Run through the part that satisfy the predicate
0033     for ( ; first != last; ++first )
0034         if ( !p (*first))
0035             break;
0036 //  Now the part that does not satisfy the predicate
0037     for ( ; first != last; ++first )
0038         if ( p (*first))
0039             return false;
0040     return true;
0041 }
0042 
0043 /// \fn is_partitioned ( const Range &r, UnaryPredicate p )
0044 /// \brief Tests to see if a sequence is partitioned according to a predicate. 
0045 ///    In other words, all the items in the sequence that satisfy the predicate are at the beginning of the sequence.
0046 /// 
0047 /// \param r        The input range
0048 /// \param p        The predicate to test the values with
0049 ///
0050 template <typename Range, typename UnaryPredicate>
0051 BOOST_CXX14_CONSTEXPR bool is_partitioned ( const Range &r, UnaryPredicate p )
0052 {
0053     return boost::algorithm::is_partitioned (boost::begin(r), boost::end(r), p);
0054 }
0055 
0056 
0057 }}
0058 
0059 #endif  // BOOST_ALGORITHM_IS_PARTITIONED_HPP