]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /* |
2 | Copyright (c) Marshall Clow 2011-2012. | |
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 partition_copy.hpp | |
9 | /// \brief Copy a subset of a sequence to a new sequence | |
10 | /// \author Marshall Clow | |
11 | ||
12 | #ifndef BOOST_ALGORITHM_PARTITION_COPY_HPP | |
13 | #define BOOST_ALGORITHM_PARTITION_COPY_HPP | |
14 | ||
15 | #include <utility> // for std::pair | |
16 | ||
17 | #include <boost/range/begin.hpp> | |
18 | #include <boost/range/end.hpp> | |
19 | ||
20 | namespace boost { namespace algorithm { | |
21 | ||
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. | |
27 | /// | |
28 | /// | |
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. | |
34 | /// | |
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 ) | |
41 | { | |
42 | for ( ; first != last; ++first ) | |
43 | if ( p (*first)) | |
44 | *out_true++ = *first; | |
45 | else | |
46 | *out_false++ = *first; | |
47 | return std::pair<OutputIterator1, OutputIterator2> ( out_true, out_false ); | |
48 | } | |
49 | ||
50 | /// \fn partition_copy ( const Range &r, | |
51 | /// OutputIterator1 out_true, OutputIterator2 out_false, UnaryPredicate p ) | |
52 | /// | |
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. | |
57 | /// | |
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, | |
62 | UnaryPredicate p ) | |
63 | { | |
64 | return boost::algorithm::partition_copy | |
65 | (boost::begin(r), boost::end(r), out_true, out_false, p ); | |
66 | } | |
67 | ||
68 | }} // namespace boost and algorithm | |
69 | ||
70 | #endif // BOOST_ALGORITHM_PARTITION_COPY_HPP |