Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.45 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <map>
  4. #include <initializer_list>
  5. #include <utility>
  6.  
  7. using namespace std;
  8.  
  9. class vect : public vector<int> {
  10. public:
  11.     //using vector::vector;
  12.     template <size_t N>
  13.     vect(const char (&s)[N]) : vector(s, s+N-1) {cout << "char[]" << endl;}
  14.     vect() : vector()  {cout << "default" << endl;};
  15.     ~vect() {cout << "destructor" << endl;};
  16.     //vect(initializer_list<int> il) : vector(move(il)) {cout << "initializer_list" << endl;}; как лучше здесь...
  17.     vect(initializer_list<int> il) : vector(il.begin(), il.end()) {cout << "initializer_list" << endl;}; // в STL у меня он и так сразу вызывает _M_range_initialize(__l.begin(), __l.end(), ...
  18.     vect(vect&& v) : vector(move(v)) {cout << "move" << endl;}
  19.     vect(const vect& v) : vector(v) {cout << "copy" << endl;}
  20.     vect& operator=(const vect& a) {vector::operator=(a); cout << "=copy" << endl; return *this;}
  21.     vect& operator=(vect&& a) {vector::operator=(move(a)); cout << "=move" << endl; return *this;}
  22. };
  23.  
  24. map<int, vect> M()
  25. {
  26.     return { {1, {1,2,3}}, {2, {4,5}}, {3, {6,7,8,9}} };
  27. }
  28.  
  29. map<int, vect> Mm()
  30. {
  31.     return { {1, move<vect>({1,2,3})}, {2, move<vect>({4,5})}, {3, move<vect>({6,7,8,9})} };
  32. }
  33.  
  34. map<int, vect> Mmm()
  35. {
  36.     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})}) };
  37. }
  38.  
  39. map<int, vect> Ms()
  40. {
  41.     return { {1, "123"}, {2, "45"}, {3, "6789"} };
  42. }
  43.  
  44. map<int, vect> Msm()
  45. {
  46.     return { {1, move<vect>("123")}, {2, move<vect>("45")}, {3, move<vect>("6789")} };
  47. }
  48.  
  49. map<int, vect> Msm2()
  50. {
  51.     return { move<pair<int,vect>>({1, "123"}), move<pair<int,vect>>({2, "45"}), move<pair<int,vect>>({3, "6789"}) };
  52. }
  53.  
  54. vect f0()
  55. {
  56.     return {1,2,3};
  57. }
  58.  
  59. vector<vect> Vmm()
  60. {
  61.     return move<vector<vect>>({move<vect>({1,2,3}), move<vect>({4,5}), move<vect>({6,7,8,9})});
  62. }
  63.  
  64. vector<vect> Vm()
  65. {
  66.     return {move<vect>({1,2,3}), move<vect>({4,5}), move<vect>({6,7,8,9})};
  67. }
  68.  
  69. vector<vect> V()
  70. {
  71.     return {{1,2,3}, {4,5}, {6,7,8,9}};
  72. }
  73.  
  74. pair<vect,int> p()
  75. {
  76.     return {{4,5,6},7};
  77. }
  78.  
  79. //pair<const vect,int> pm() -- результат тот же
  80. pair<vect,int> pm()
  81. {
  82.     return {move<vect>({4,5,6}),7};
  83. }
  84.  
  85.  
  86. int main()
  87. {
  88.     auto x = M();
  89.     for (auto&& p : x) {cout << p.first << ": "; for (int i : p.second) cout << i << ' '; cout << '\n';}
  90.     return 0;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement