STL algorithm算法copy_if(8)

2015-07-20 17:43:58 · 作者: · 浏览: 5
?

std::copy_if

template 
   
    
  OutputIterator copy_if (InputIterator first, InputIterator last,
                          OutputIterator result, UnaryPredicate pred);

   
Copy certain elements of range

Copies the elements in the range [first,last) for which pred returns true to the range beginning at result.

将符合要求的元素(对元素调用pred返回true的元素)复制到目标数组中。


The behavior of this function template is equivalent to:
1
2
3
4
5
6
7
8
9
10
11
12
13
template <class InputIterator, class OutputIterator, class UnaryPredicate>
  OutputIterator copy_if (InputIterator first, InputIterator last,
                          OutputIterator result, UnaryPredicate pred)
{
  while (first!=last) {
    if (pred(*first)) {
      *result = *first;
      ++result;
    }
    ++first;
  }
  return result;
}
?


Parameters