forked from Bhupesh-V/30-seconds-of-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
remove_copy.cpp
34 lines (29 loc) · 852 Bytes
/
remove_copy.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*
Author : Thamara Andrade
Date : Date format 09/09/2019
Time : Time format 23:00
Description : Removes elements from vector that satisfies a criteria.
*/
#include <iostream>
#include <vector>
#include <algorithm>
int main()
{
std::vector<int> origin {3, 5, 3, 1, 2, 3};
std::vector<int> destination;
// Copy elements to destination that are not 3
std::remove_copy(origin.begin(), //first
origin.end(), //last
std::back_inserter(destination), //d_first
3);
// origin is still {3, 5, 3, 1, 2, 3}
for (auto value : origin) {
std::cout << value << " ";
}
std::cout << std::endl;
// destination is {5, 1, 2}
for (auto value : destination) {
std::cout << value << " ";
}
std::cout << std::endl;
}