The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.



In a range of elements, copies the elements that are true for the specified condition.

template<class InputIterator, class OutputIterator, class BinaryPredicate>
   OutputIterator copy_if(
      InputIterator _First, 
      InputIterator _Last,
      OutputIterator _Dest,
      Predicate _Pred


An input iterator that indicates the start of a range to check for the condition.


An input iterator that indicates the end of the range.


The output iterator that indicates the destination for the copied elements.


The condition against which every element in the range is tested. This condition is provided by a user-defined predicate function object. A predicate takes one argument and returns true or false.

An output iterator that equals _Dest incremented once for each element that fulfills the condition. In other words, the return value minus _Dest equals the number of copied elements.

The template function evaluates

if (_Pred(*_First + N))

*_Dest++ = *(_First + N))

once for each N in the range [0, _Last - _First), for strictly increasing values of N starting with the lowest value. If _Dest and _First designate regions of storage, _Dest must not be in the range [_First, _Last).


Header: <algorithm>

Namespace: std