Chris@16: /* Chris@16: Copyright (c) Marshall Clow 2011-2012. Chris@16: Chris@16: Distributed under the Boost Software License, Version 1.0. (See accompanying Chris@16: file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: */ Chris@16: Chris@16: /// \file partition_copy.hpp Chris@16: /// \brief Copy a subset of a sequence to a new sequence Chris@16: /// \author Marshall Clow Chris@16: Chris@16: #ifndef BOOST_ALGORITHM_PARTITION_COPY_HPP Chris@16: #define BOOST_ALGORITHM_PARTITION_COPY_HPP Chris@16: Chris@16: #include // for std::partition_copy, if available Chris@16: #include // for make_pair Chris@16: Chris@16: #include Chris@16: #include Chris@16: Chris@16: namespace boost { namespace algorithm { Chris@16: Chris@16: /// \fn partition_copy ( InputIterator first, InputIterator last, Chris@16: /// OutputIterator1 out_true, OutputIterator2 out_false, UnaryPredicate p ) Chris@16: /// \brief Copies the elements that satisfy the predicate p from the range [first, last) Chris@16: /// to the range beginning at d_first_true, and Chris@16: /// copies the elements that do not satisfy p to the range beginning at d_first_false. Chris@16: /// Chris@16: /// Chris@16: /// \param first The start of the input sequence Chris@16: /// \param last One past the end of the input sequence Chris@16: /// \param out_true An output iterator to write the elements that satisfy the predicate into Chris@16: /// \param out_false An output iterator to write the elements that do not satisfy the predicate into Chris@16: /// \param p A predicate for dividing the elements of the input sequence. Chris@16: /// Chris@16: /// \note This function is part of the C++2011 standard library. Chris@16: /// We will use the standard one if it is available, Chris@16: /// otherwise we have our own implementation. Chris@16: template Chris@16: std::pair Chris@16: partition_copy ( InputIterator first, InputIterator last, Chris@16: OutputIterator1 out_true, OutputIterator2 out_false, UnaryPredicate p ) Chris@16: { Chris@16: for ( ; first != last; ++first ) Chris@16: if ( p (*first)) Chris@16: *out_true++ = *first; Chris@16: else Chris@16: *out_false++ = *first; Chris@16: return std::pair ( out_true, out_false ); Chris@16: } Chris@16: Chris@16: /// \fn partition_copy ( const Range &r, Chris@16: /// OutputIterator1 out_true, OutputIterator2 out_false, UnaryPredicate p ) Chris@16: /// Chris@16: /// \param r The input range Chris@16: /// \param out_true An output iterator to write the elements that satisfy the predicate into Chris@16: /// \param out_false An output iterator to write the elements that do not satisfy the predicate into Chris@16: /// \param p A predicate for dividing the elements of the input sequence. Chris@16: /// Chris@16: template Chris@16: std::pair Chris@16: partition_copy ( const Range &r, OutputIterator1 out_true, OutputIterator2 out_false, Chris@16: UnaryPredicate p ) Chris@16: { Chris@16: return boost::algorithm::partition_copy Chris@16: (boost::begin(r), boost::end(r), out_true, out_false, p ); Chris@16: } Chris@16: Chris@16: }} // namespace boost and algorithm Chris@16: Chris@16: #endif // BOOST_ALGORITHM_PARTITION_COPY_HPP