2 Copyright (c) Marshall Clow 2011-2012.
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)
8 /// \file partition_copy.hpp
9 /// \brief Copy a subset of a sequence to a new sequence
10 /// \author Marshall Clow
12 #ifndef BOOST_ALGORITHM_PARTITION_COPY_HPP
13 #define BOOST_ALGORITHM_PARTITION_COPY_HPP
15 #include <utility> // for std::pair
17 #include <boost/range/begin.hpp>
18 #include <boost/range/end.hpp>
20 namespace boost { namespace algorithm {
22 /// \fn partition_copy ( InputIterator first, InputIterator last,
23 /// OutputIterator1 out_true, OutputIterator2 out_false, UnaryPredicate p )
24 /// \brief Copies the elements that satisfy the predicate p from the range [first, last)
25 /// to the range beginning at d_first_true, and
26 /// copies the elements that do not satisfy p to the range beginning at d_first_false.
29 /// \param first The start of the input sequence
30 /// \param last One past the end of the input sequence
31 /// \param out_true An output iterator to write the elements that satisfy the predicate into
32 /// \param out_false An output iterator to write the elements that do not satisfy the predicate into
33 /// \param p A predicate for dividing the elements of the input sequence.
35 /// \note This function is part of the C++2011 standard library.
36 template <typename InputIterator,
37 typename OutputIterator1, typename OutputIterator2, typename UnaryPredicate>
38 std::pair<OutputIterator1, OutputIterator2>
39 partition_copy ( InputIterator first, InputIterator last,
40 OutputIterator1 out_true, OutputIterator2 out_false, UnaryPredicate p )
42 for ( ; first != last; ++first )
46 *out_false++ = *first;
47 return std::pair<OutputIterator1, OutputIterator2> ( out_true, out_false );
50 /// \fn partition_copy ( const Range &r,
51 /// OutputIterator1 out_true, OutputIterator2 out_false, UnaryPredicate p )
53 /// \param r The input range
54 /// \param out_true An output iterator to write the elements that satisfy the predicate into
55 /// \param out_false An output iterator to write the elements that do not satisfy the predicate into
56 /// \param p A predicate for dividing the elements of the input sequence.
58 template <typename Range, typename OutputIterator1, typename OutputIterator2,
59 typename UnaryPredicate>
60 std::pair<OutputIterator1, OutputIterator2>
61 partition_copy ( const Range &r, OutputIterator1 out_true, OutputIterator2 out_false,
64 return boost::algorithm::partition_copy
65 (boost::begin(r), boost::end(r), out_true, out_false, p );
68 }} // namespace boost and algorithm
70 #endif // BOOST_ALGORITHM_PARTITION_COPY_HPP