Debian Codegraph @

yo/advancedtemplates/examples/vector0.cc

raw
1 #include <iostream>
2 #include <string>
3 #include <vector>
4 #include <algorithm>
5
6 using namespace std;
7
8 //regex s_inetAddr(R"(^\s+inet addr:(\S+))");
9
10 struct VI: public vector<int>
11 {
12 int d_v = 1;
13
14 VI()
15 {
16 cout << "VI default\n";
17 }
18 ~VI()
19 {
20 }
21 VI(VI const &other)
22 :
23 vector<int>(other),
24 d_v(other.d_v)
25 {
26 cout << "VI copycons\n";
27 }
28 VI(VI &&tmp)
29 :
30 vector<int>(std::move(tmp)),
31 d_v(tmp.d_v)
32 {
33 cout << "VI move cons\n";
34 }
35
36 VI &operator=(VI const &other)
37 {
38 VI tmp{ other };
39 swap(tmp);
40 return *this;
41 }
42
43 void swap(VI &other)
44 {
45 std::swap(d_v, other.d_v);
46 static_cast<vector<int> &>(*this).swap(other);
47 }
48
49 VI &operator+=(VI const &rhs)
50 {
51 d_v += rhs.d_v;
52 return *this;
53 }
54 VI &operator+=(VI &&tmp)
55 {
56 d_v += tmp.d_v;
57 return *this;
58 }
59 };
60
61 VI operator+(VI const &lhs, VI const &rhs)
62 {
63 VI tmp{ lhs };
64
65 cout << "adding, returning new object\n";
66
67 tmp += rhs;
68 return tmp;
69 }
70
71 VI &&operator+(VI &&tmp, VI const &rhs)
72 {
73 cout << "adding, returning available temporary object\n";
74 tmp += rhs;
75 return std::move(tmp);
76 }
77
78 int main()
79 {
80 VI a, b, c, d;
81
82 d = a + b + c + d + a + b + c + d;
83 }