-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
259 lines (199 loc) · 6.57 KB
/
Copy pathmain.cpp
File metadata and controls
259 lines (199 loc) · 6.57 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
#include "traits/type_trait.h"
#include "tests/test.h"
#include "tools/logger.h"
#include "base/Option.h"
extern void test_collect();
extern void test_container();
template<typename T>
T *get_address(T &t) {
return &t;
}
template<typename T>
const T *get_address(const T &t) {
return &t;
}
void test_rref(int &&v) {
Log(Trace) << v << std::endl;
}
struct Ta {
int a;
double b;
};
int main() {
log.set_level(Trace);
closure_param_type_t<decltype([](double) {
})> df = 2.4;
Log(Trace) << df << std::endl;
int aa = 0;
int *ar = &aa;
const int bb = 0;
auto io = Option<int>(6);
auto lo = Option<int>(aa);
auto ro = Option<int &>(aa);
auto po = Option<int *>(ar);
auto const_io = Option<const int*>(&bb);
const_io.get() += 1;
auto empty = Option<int>();
// io.get() += 1;
// lo.get() += 1;
// ro.get() += 1;
// po.get() += 1;
// assert(io.has_value() && lo.has_value() && ro.has_value() && po.has_value());
// *io;
// *lo;
// *ro;
// *po;
Ta ta{};
auto co = Option<Ta>(ta);
co->a;
if (po.get() == ar + 1) {
Log(Trace) << "this is address: " << po.get() << std::endl;
}
ro.get() += 1;
Log(Trace) << ro.get() << std::endl;
Log(Trace) << aa << std::endl;
// test_cell();
// test_make_union();
// test_raw_union();
// test_chunk();
// test_iter();
// test::iterator::test_zip();
// test::test_raw_iterator();
// test::iterator::test_for_each();
// test::iterator::test_adapter();
// test::tools::test_printf();
// test::iterator::test_zip();
// test::iterator::test_raw_zip();
// test::iterator::test_common();
// test::iterator::test_construct();
// test::iterator::test_const_iterator();
// test::iterator::test_mut_iterator();
// test::iterator::test_consume_iterator();
test::array::test_crtp();
// test::crtp_iterator::test_crtp();
// test::iterator::benchmark();
// test::iterator::test_step();
// test::iterator::test_filter();
// test::iterator::test_windows();
// auto f = test::iterator::create_foo();
// test::iterator::test_bad(std::move(f));
// int a = 5;
// int b = 10;
// test_rref(5);
// not correct
// std::pair<int, int &> p = std::make_pair(a, a);
// std::pair<int, int &> p = {a, a};
// int &ar = a;
// int &br = b;
// std::vector<int &> vr = {ar, br};
// RawZipIterator<Cell<int>, Ref<int>>* v = nullptr;
// auto int_array = IntArray<5>{4, 5, 6, 7, 8};
// auto rri = int_array.iter_ref_raw();
// RawIterator<Ref<int> > &ari = rri;
// test_trait(int_array.iter_ptr());
// test base iterator
// Iterator<int> *it = new ArrayIterator(int_array.iter());
// for (int i = 0; i < 4; i++) {
// auto v = it->next();
// *v = i;
// Log(Trace) << (v.has_value() ? "Some" : "None") << ", v: " << v.value() << std::endl;
// }
// delete it;
// int_array
// .iter_mut()
// .for_each([](auto &v) {
// Printer::println(v++);
// });
// print_array(int_array);
// test
// BoundedRange range(4, 10);
// auto range_it = range.iter();
// Iterator<int> *it = &range_it;
// auto c = int_array.iter().count();
// Log(Trace) << c << std::endl;
// std::vector<std::string> strs{"abc", "def", "ghi", "jkl"};
// const auto &sl = iter(strs).last();
// Log(Trace) << "last: " << sl.value() << std::endl;
// auto joins = iter(strs)
// .fold(std::string{}, [](const std::string &acc, const std::string &i) { return acc + "+" + i; });
// Log(Trace) << joins << std::endl;
//
// auto ns = iter(strs)
// .map([](const auto &i) { i[0] += 1;return i.substr(0, 2);})
// .collect<std::vector<std::string> >();
// print_array(ns);
// Log(Trace) << ns << std::endl;
// for (const auto &i: strs) {
// Log(Trace) << "debug: " << i << std::endl;
// }
//
// std::string start{};
// iter(strs)
// .fold_on_place(start, [](std::string &acc, const std::string &i) {
// acc += "+";
// Log(Trace) << i << std::endl;
// acc += i;
// });
// Log(Trace) << start << std::endl;
// test
// const int sum = int_array.iter().skip(2).fold(0, [](int acc, int &v) { return acc + v; });
// Log(Trace) << "sum: " << sum << std::endl;
// test collect
// auto container = int_array
// .iter()
// .enumerate()
// .skip(1)
// .take(2)
// .collect<std::vector<std::pair<int, int> > >();
// for (auto v: container) {
// Log(Trace) << v.first << " : " << v.second << std::endl;
// }
// test stl iterator
// {
// auto start = std::begin(container);
// auto end = std::end(container);
// for (auto it = start; it != end; ++it) {
// Log(Trace) << "key: " << it->first << std::endl;
// }
// }
// test stl iterator adapter
// std::vector<int> v{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
// // std::array<int, 5> v{11, 12, 13, 14, 15};
// // std::string v{"Hello, World!"};
// iter(v)
// .filter([](const int &v) { return v % 2 == 0; })
// .map([](const int v) { return v * v; })
// .for_each([](auto &v) {
// Log(Trace) << "val: " << v << std::endl;
// });
//
// std::string s{"abcdefg"};
// const auto new_str = iter(s).map([](char v) { return char(v + 1); }).collect<std::string>();
// Log(Trace) << "new_str: " << new_str << std::endl;
// test union iter() interface
// iter(v)
// .enumerate()
// .filter([](auto &p) {
// auto &[k, v] = p;
// return k % 2 == 0;
// })
// .for_each(Printer::println);
// iter(5);
// test_iterator_trait(iter(v));
// test_iterator_trait(int_array.iter());
// std::array arr{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
// test_container()
// test complicated class
// std::unordered_map<int, const char *> map{{1, "one"}, {2, "two"}, {3, "three"}};
// const std::string sum1 = iter(map)
// .map([](const auto &v) {
// const auto &[key, val] = v;
// return std::to_string(key) + ':' + val + ",";
// })
// .fold(std::string(), [](auto acc, auto &v) {
// return acc + v;
// });
// Printer::print("the map keys sum: ");
// Printer::println(sum1);
return 0;
}