Debian Codegraph @

yo/advancedtemplates/examples/vector.cc

raw
1 #include <iostream>
2 #include <string>
3 #include <vector>
4
5 using namespace std;
6
7 struct VI: public vector<int>
8 {
9 static size_t const s_max = 10000;
10 VI()
11 :
12 vector<int>(s_max, 1)
13 {}
14
15 VI &operator+=(VI const &rhs)
16 {
17 for (size_t idx = 0; idx != s_max; ++idx)
18 (*this)[idx] += rhs[idx];
19
20 return *this;
21 }
22 };
23
24 VI operator+(VI const &lhs, VI const &rhs)
25 {
26 VI tmp{ lhs };
27
28 tmp += rhs;
29 return tmp;
30 }
31
32 VI &&operator+(VI &&tmp, VI const &rhs)
33 {
34 tmp += rhs;
35 return std::move(tmp);
36 }
37
38 int main(int argc, char **argv)
39 {
40 VI a, b, c, d;
41
42 for (size_t idx = 0, count = stoul(argv[1]); idx != count; ++idx)
43 d = a + b + c + d + a + b + c + d;
44
45 cout << d.front() << ", " << d.back() << '\n';
46 }