forked from Bhupesh-V/30-seconds-of-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcopy_if.cpp
More file actions
28 lines (23 loc) 路 673 Bytes
/
Copy pathcopy_if.cpp
File metadata and controls
28 lines (23 loc) 路 673 Bytes
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
/*
Author : Thamara Andrade
Date : Date format 02/09/2019
Time : Time format 02:00
Description : Copies the elements in one range to another range if it matches a condition.
*/
#include <iostream>
#include <vector>
#include <algorithm>
int main()
{
auto isOdd = [](int i) {
return ((i%2) == 1);
};
std::vector<int> origin {1, 2, 3};
std::vector<int> destination;
// Will copy from origin [begin, end), to destination
std::copy_if(origin.begin(), origin.end(), std::back_inserter(destination), isOdd);
// destination is now {1, 3}
for (auto value : destination) {
std::cout << value << " ";
}
}