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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
#include <iostream>
#include <memory>
#include <type_traits>
#include <utility>
#include <vector>
#include <cmext/algorithm>
namespace {
int failed = 0;
void testAppend()
{
std::cout << "testAppend()" << std::endl;
// ----------------------------------------------------
// cm::append(Vector, Iterator, Iterator)
{
std::vector<int> v1{ 1, 2, 3 };
std::vector<int> v1_ref{ 1, 2, 3, 4, 5, 6 };
std::vector<int> v2{ 4, 5, 6 };
std::vector<int> v2_ref{ 4, 5, 6 };
cm::append(v1, v2.begin(), v2.end());
if (v1 != v1_ref || v2 != v2_ref) {
++failed;
}
}
// ----------------------------------------------------
// cm::append(Vector, Range)
{
std::vector<int> v1{ 1, 2, 3 };
std::vector<int> v1_ref{ 1, 2, 3, 4, 5, 6 };
std::vector<int> v2{ 4, 5, 6 };
std::vector<int> v2_ref{ 4, 5, 6 };
cm::append(v1, v2);
if (v1 != v1_ref || v2 != v2_ref) {
++failed;
}
}
// ----------------------------------------------------
// cm::append(Vector<*>, Vector<unique_ptr>)
{
std::vector<int*> v1{ new int(1), new int(2), new int(3) };
std::vector<int*> v1_ref = v1;
std::vector<std::unique_ptr<int>> v2;
v2.emplace_back(new int(4));
v2.emplace_back(new int(5));
v2.emplace_back(new int(6));
cm::append(v1, v2);
if (v1.size() == 6 && v2.size() == 3) {
for (int i = 0; i < 3; i++) {
if (v1[i] != v1_ref[i]) {
++failed;
break;
}
}
for (int i = 0; i < 3; i++) {
if (v1[i + 3] != v2[i].get()) {
++failed;
break;
}
}
} else {
++failed;
}
// free memory to please memory sanitizer
delete v1[0];
delete v1[1];
delete v1[2];
}
// ----------------------------------------------------
// cm::append(Vector<unique_ptr>, Vector<unique_ptr>)
{
std::vector<std::unique_ptr<int>> v1;
std::vector<std::unique_ptr<int>> v2;
v1.emplace_back(new int(1));
v1.emplace_back(new int(2));
v1.emplace_back(new int(3));
v2.emplace_back(new int(4));
v2.emplace_back(new int(5));
v2.emplace_back(new int(6));
cm::append(v1, std::move(v2));
if (v1.size() == 6 && v2.empty()) {
for (int i = 0; i < 6; i++) {
if (*v1[i] != i + 1) {
++failed;
break;
}
}
} else {
++failed;
}
}
}
}
int testCMExtAlgorithm(int /*unused*/, char* /*unused*/ [])
{
testAppend();
return failed;
}
|