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_copy.hpp
0009 /// \brief Copy a subset of a sequence to a new sequence
0010 /// \author Marshall Clow
0011 
0012 #ifndef BOOST_ALGORITHM_PARTITION_COPY_HPP
0013 #define BOOST_ALGORITHM_PARTITION_COPY_HPP
0014 
0015 #include <utility>  // for std::pair
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_copy ( InputIterator first, InputIterator last,
0024 ///     OutputIterator1 out_true, OutputIterator2 out_false, UnaryPredicate p )
0025 /// \brief Copies the elements that satisfy the predicate p from the range [first, last) 
0026 ///     to the range beginning at d_first_true, and
0027 ///     copies the elements that do not satisfy p to the range beginning at d_first_false.
0028 ///
0029 /// 
0030 /// \param first     The start of the input sequence
0031 /// \param last      One past the end of the input sequence
0032 /// \param out_true  An output iterator to write the elements that satisfy the predicate into
0033 /// \param out_false An output iterator to write the elements that do not satisfy the predicate into
0034 /// \param p         A predicate for dividing the elements of the input sequence.
0035 ///
0036 /// \note            This function is part of the C++2011 standard library.
0037 template <typename InputIterator, 
0038         typename OutputIterator1, typename OutputIterator2, typename UnaryPredicate>
0039 BOOST_CXX14_CONSTEXPR std::pair<OutputIterator1, OutputIterator2>
0040 partition_copy ( InputIterator first, InputIterator last,
0041         OutputIterator1 out_true, OutputIterator2 out_false, UnaryPredicate p )
0042 {
0043     for ( ; first != last; ++first )
0044         if ( p (*first))
0045             *out_true++ = *first;
0046         else
0047             *out_false++ = *first;
0048     return std::pair<OutputIterator1, OutputIterator2> ( out_true, out_false );
0049 }
0050 
0051 /// \fn partition_copy ( const Range &r, 
0052 ///     OutputIterator1 out_true, OutputIterator2 out_false, UnaryPredicate p )
0053 /// 
0054 /// \param r         The input range
0055 /// \param out_true  An output iterator to write the elements that satisfy the predicate into
0056 /// \param out_false An output iterator to write the elements that do not satisfy the predicate into
0057 /// \param p         A predicate for dividing the elements of the input sequence.
0058 ///
0059 template <typename Range, typename OutputIterator1, typename OutputIterator2, 
0060             typename UnaryPredicate>
0061 BOOST_CXX14_CONSTEXPR std::pair<OutputIterator1, OutputIterator2>
0062 partition_copy ( const Range &r, OutputIterator1 out_true, OutputIterator2 out_false, 
0063                                 UnaryPredicate p )
0064 {
0065     return boost::algorithm::partition_copy 
0066                       (boost::begin(r), boost::end(r), out_true, out_false, p );
0067 }
0068 
0069 }} // namespace boost and algorithm
0070 
0071 #endif  // BOOST_ALGORITHM_PARTITION_COPY_HPP