Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <map>
- #include <initializer_list>
- #include <utility>
- using namespace std;
- class vect : public vector<int> {
- public:
- //using vector::vector;
- template <size_t N>
- vect(const char (&s)[N]) : vector(s, s+N-1) {cout << "char[]" << endl;}
- vect() : vector() {cout << "default" << endl;};
- ~vect() {cout << "destructor" << endl;};
- //vect(initializer_list<int> il) : vector(move(il)) {cout << "initializer_list" << endl;}; как лучше здесь...
- vect(initializer_list<int> il) : vector(il.begin(), il.end()) {cout << "initializer_list" << endl;}; // в STL у меня он и так сразу вызывает _M_range_initialize(__l.begin(), __l.end(), ...
- vect(vect&& v) : vector(move(v)) {cout << "move" << endl;}
- vect(const vect& v) : vector(v) {cout << "copy" << endl;}
- vect& operator=(const vect& a) {vector::operator=(a); cout << "=copy" << endl; return *this;}
- vect& operator=(vect&& a) {vector::operator=(move(a)); cout << "=move" << endl; return *this;}
- };
- map<int, vect> M()
- {
- return { {1, {1,2,3}}, {2, {4,5}}, {3, {6,7,8,9}} };
- }
- map<int, vect> Mm()
- {
- return { {1, move<vect>({1,2,3})}, {2, move<vect>({4,5})}, {3, move<vect>({6,7,8,9})} };
- }
- map<int, vect> Mmm()
- {
- return { move<pair<int,vect>>({1, move<vect>({1,2,3})}), move<pair<int,vect>>({2, move<vect>({4,5})}), move<pair<int,vect>>({3, move<vect>({6,7,8,9})}) };
- }
- map<int, vect> Ms()
- {
- return { {1, "123"}, {2, "45"}, {3, "6789"} };
- }
- map<int, vect> Msm()
- {
- return { {1, move<vect>("123")}, {2, move<vect>("45")}, {3, move<vect>("6789")} };
- }
- map<int, vect> Msm2()
- {
- return { move<pair<int,vect>>({1, "123"}), move<pair<int,vect>>({2, "45"}), move<pair<int,vect>>({3, "6789"}) };
- }
- vect f0()
- {
- return {1,2,3};
- }
- vector<vect> Vmm()
- {
- return move<vector<vect>>({move<vect>({1,2,3}), move<vect>({4,5}), move<vect>({6,7,8,9})});
- }
- vector<vect> Vm()
- {
- return {move<vect>({1,2,3}), move<vect>({4,5}), move<vect>({6,7,8,9})};
- }
- vector<vect> V()
- {
- return {{1,2,3}, {4,5}, {6,7,8,9}};
- }
- pair<vect,int> p()
- {
- return {{4,5,6},7};
- }
- //pair<const vect,int> pm() -- результат тот же
- pair<vect,int> pm()
- {
- return {move<vect>({4,5,6}),7};
- }
- int main()
- {
- auto x = M();
- for (auto&& p : x) {cout << p.first << ": "; for (int i : p.second) cout << i << ' '; cout << '\n';}
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement