]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/algorithm/cxx11/copy_if.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / algorithm / cxx11 / copy_if.hpp
CommitLineData
7c673cae
FG
1/*
2 Copyright (c) Marshall Clow 2008-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 copy_if.hpp
9/// \brief Copy a subset of a sequence to a new sequence
10/// \author Marshall Clow
11
12#ifndef BOOST_ALGORITHM_COPY_IF_HPP
13#define BOOST_ALGORITHM_COPY_IF_HPP
14
15#include <utility> // for std::pair, std::make_pair
92f5a8d4
TL
16
17#include <boost/config.hpp>
7c673cae
FG
18#include <boost/range/begin.hpp>
19#include <boost/range/end.hpp>
20
21namespace boost { namespace algorithm {
22
23/// \fn copy_if ( InputIterator first, InputIterator last, OutputIterator result, Predicate p )
24/// \brief Copies all the elements from the input range that satisfy the
25/// predicate to the output range.
26/// \return The updated output iterator
27///
28/// \param first The start of the input sequence
29/// \param last One past the end of the input sequence
30/// \param result An output iterator to write the results into
31/// \param p A predicate for testing the elements of the range
32/// \note This function is part of the C++2011 standard library.
33template<typename InputIterator, typename OutputIterator, typename Predicate>
92f5a8d4 34BOOST_CXX14_CONSTEXPR OutputIterator copy_if ( InputIterator first, InputIterator last, OutputIterator result, Predicate p )
7c673cae
FG
35{
36 for ( ; first != last; ++first )
37 if (p(*first))
38 *result++ = *first;
39 return result;
40}
41
42/// \fn copy_if ( const Range &r, OutputIterator result, Predicate p )
43/// \brief Copies all the elements from the input range that satisfy the
44/// predicate to the output range.
45/// \return The updated output iterator
46///
47/// \param r The input range
48/// \param result An output iterator to write the results into
49/// \param p A predicate for testing the elements of the range
50///
51template<typename Range, typename OutputIterator, typename Predicate>
92f5a8d4 52BOOST_CXX14_CONSTEXPR OutputIterator copy_if ( const Range &r, OutputIterator result, Predicate p )
7c673cae
FG
53{
54 return boost::algorithm::copy_if (boost::begin (r), boost::end(r), result, p);
55}
56
57
58/// \fn copy_while ( InputIterator first, InputIterator last, OutputIterator result, Predicate p )
59/// \brief Copies all the elements at the start of the input range that
60/// satisfy the predicate to the output range.
61/// \return The updated input and output iterators
62///
63/// \param first The start of the input sequence
64/// \param last One past the end of the input sequence
65/// \param result An output iterator to write the results into
66/// \param p A predicate for testing the elements of the range
67///
68template<typename InputIterator, typename OutputIterator, typename Predicate>
92f5a8d4 69BOOST_CXX14_CONSTEXPR std::pair<InputIterator, OutputIterator>
7c673cae
FG
70copy_while ( InputIterator first, InputIterator last, OutputIterator result, Predicate p )
71{
72 for ( ; first != last && p(*first); ++first )
73 *result++ = *first;
74 return std::make_pair(first, result);
75}
76
77/// \fn copy_while ( const Range &r, OutputIterator result, Predicate p )
78/// \brief Copies all the elements at the start of the input range that
79/// satisfy the predicate to the output range.
80/// \return The updated input and output iterators
81///
82/// \param r The input range
83/// \param result An output iterator to write the results into
84/// \param p A predicate for testing the elements of the range
85///
86template<typename Range, typename OutputIterator, typename Predicate>
92f5a8d4 87BOOST_CXX14_CONSTEXPR std::pair<typename boost::range_iterator<const Range>::type, OutputIterator>
7c673cae
FG
88copy_while ( const Range &r, OutputIterator result, Predicate p )
89{
90 return boost::algorithm::copy_while (boost::begin (r), boost::end(r), result, p);
91}
92
93
94/// \fn copy_until ( InputIterator first, InputIterator last, OutputIterator result, Predicate p )
95/// \brief Copies all the elements at the start of the input range that do not
96/// satisfy the predicate to the output range.
97/// \return The updated output iterator
98///
99/// \param first The start of the input sequence
100/// \param last One past the end of the input sequence
101/// \param result An output iterator to write the results into
102/// \param p A predicate for testing the elements of the range
103///
104template<typename InputIterator, typename OutputIterator, typename Predicate>
92f5a8d4 105BOOST_CXX14_CONSTEXPR std::pair<InputIterator, OutputIterator>
7c673cae
FG
106copy_until ( InputIterator first, InputIterator last, OutputIterator result, Predicate p )
107{
108 for ( ; first != last && !p(*first); ++first )
109 *result++ = *first;
110 return std::make_pair(first, result);
111}
112
113/// \fn copy_until ( const Range &r, OutputIterator result, Predicate p )
114/// \brief Copies all the elements at the start of the input range that do not
115/// satisfy the predicate to the output range.
116/// \return The updated output iterator
117///
118/// \param r The input range
119/// \param result An output iterator to write the results into
120/// \param p A predicate for testing the elements of the range
121///
122template<typename Range, typename OutputIterator, typename Predicate>
92f5a8d4 123BOOST_CXX14_CONSTEXPR std::pair<typename boost::range_iterator<const Range>::type, OutputIterator>
7c673cae
FG
124copy_until ( const Range &r, OutputIterator result, Predicate p )
125{
126 return boost::algorithm::copy_until (boost::begin (r), boost::end(r), result, p);
127}
128
129}} // namespace boost and algorithm
130
131#endif // BOOST_ALGORITHM_COPY_IF_HPP