forked from n3554/n3554
-
Notifications
You must be signed in to change notification settings - Fork 0
/
unique.cpp
40 lines (32 loc) · 864 Bytes
/
unique.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
35
36
37
38
39
#include <algorithm>
#include <vector>
#include <numeric>
#include <functional>
#include <iostream>
int main()
{
std::vector<int> vec(10, 1);
std::vector<int> copy(10);
std::iota(vec.begin(), vec.end(), 0);
std::transform(vec.begin(), vec.end(), vec.begin(), [](int i)
{
return i / 2;
});
auto new_end = std::unique_copy(std::seq, vec.begin(), vec.end(), copy.begin(), std::equal_to<int>());
copy.erase(new_end, copy.end());
std::cout << "unique_copy result: ";
for(int i = 0; i < copy.size(); ++i)
{
std::cout << copy[i] << " ";
}
std::cout << std::endl;
new_end = std::unique(std::par, vec.begin(), vec.end(), std::equal_to<int>());
vec.erase(new_end, vec.end());
std::cout << "unique result: ";
for(int i = 0; i < vec.size(); ++i)
{
std::cout << vec[i] << " ";
}
std::cout << std::endl;
return 0;
}