-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathGenerate.cpp
More file actions
101 lines (78 loc) · 2.09 KB
/
Copy pathGenerate.cpp
File metadata and controls
101 lines (78 loc) · 2.09 KB
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
// =====================================================================================
// Generate.cpp // std::generate
// =====================================================================================
module modern_cpp:generate;
namespace AlgorithmGenerate {
static void test_01()
{
std::vector<int> values(10);
for (int i{}; i != values.size(); ++i) {
values[i] = 1;
}
std::for_each (
values.begin(),
values.end(),
[](auto n) { std::print("{} ", n); }
);
std::println();
}
static void test_02()
{
std::vector<int> values(10);
for (int i{}; i != values.size(); ++i) {
values[i] = 1;
}
std::fill(
values.begin(),
values.end(),
2
);
std::for_each(
values.begin(),
values.end(),
[](auto n) { std::print("{} ", n); }
);
std::println();
}
static void test_03()
{
std::vector<int> values(10);
std::for_each(
values.begin(),
values.end(),
[count = 1](auto& n) mutable { n = count; count++; }
);
std::for_each(
values.begin(),
values.end(),
[](int n) { std::print("{} ", n); }
);
std::cout << std::endl;
}
static void test_04()
{
std::vector<int> values(10);
std::generate(
values.begin(),
values.end(),
[count = 1]() mutable { return count++; }
);
std::for_each(
values.begin(),
values.end(),
[](auto n) { std::print("{} ", n); }
);
std::cout << std::endl;
}
}
void main_generate()
{
using namespace AlgorithmGenerate;
test_01();
test_02();
test_03();
test_04();
}
// =====================================================================================
// End-of-File
// =====================================================================================