function template
<algorithm>

# std::remove_copy

```template <class InputIterator, class OutputIterator, class T>
OutputIterator remove_copy (InputIterator first, InputIterator last,
OutputIterator result, const T& val);```
Copy range removing value
Copies the elements in the range `[first,last)` to the range beginning at result, except those elements that compare equal to val.

The resulting range is shorter than `[first,last)` by as many elements as matches in the sequence, which are "removed".

The function uses `operator==` to compare the individual elements to val.

The behavior of this function template is equivalent to:
 ``12345678910111213`` ``````template OutputIterator remove_copy (InputIterator first, InputIterator last, OutputIterator result, const T& val) { while (first!=last) { if (!(*first == val)) { *result = *first; ++result; } ++first; } return result; }``````

### Parameters

first, last
Forward iterators to the initial and final positions in a sequence of elements supporting being compared to a value of type T. The range used is `[first,last)`, which contains all the elements between first and last, including the element pointed by first but not the element pointed by last.
result
Output iterator to the initial position of the range where the resulting sequence is stored.
The pointed type shall support being assigned the value of an element in the range `[first,last)`.
val
Value to be removed.

The ranges shall not overlap.

### Return value

An iterator pointing to the end of the copied range, which includes all the elements in `[first,last)` except those that compare equal to val.

### Example

 ``123456789101112131415161718`` ``````// remove_copy example #include // std::cout #include // std::remove_copy #include // std::vector int main () { int myints[] = {10,20,30,30,20,10,10,20}; // 10 20 30 30 20 10 10 20 std::vector myvector (8); std::remove_copy (myints,myints+8,myvector.begin(),20); // 10 30 30 10 10 0 0 0 std::cout << "myvector contains:"; for (std::vector::iterator it=myvector.begin(); it!=myvector.end(); ++it) std::cout << ' ' << *it; std::cout << '\n'; return 0; }``````

Output:
 ```myvector contains: 10 30 30 10 10 0 0 0 ```

### Complexity

Linear in the distance between first and last: Compares each element, and performs an assignment operation for those not removed.

### Data races

The objects in the range `[first,last)` are accessed.
The objects in the range between result and the returned value are modified.

### Exceptions

Throws if any of the element comparisons, the element assignments or the operations on iterators throws.
Note that invalid arguments cause undefined behavior.