Advertisement
RobertDeMilo

RB5.2 Перемещение в других ситуациях

Apr 17th, 2024
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.85 KB | None | 0 0
  1. // Везде, где есть место копированию может происходить и перемещение
  2.  
  3. #include <iostream>
  4. #include <map>
  5. #include <set>
  6. #include <string>
  7. #include <vector>
  8.  
  9. using namespace std;
  10.  
  11. string MakeString()
  12. {
  13.     return string(100000000,'a');
  14. }
  15.  
  16. vector<int> MakeVector()
  17. {
  18.     return vector<int>(100000000, 0);
  19. }
  20.  
  21. int main()
  22. {
  23.     {
  24.         LOG_DURATION("assignment, with variable");
  25.  
  26.         string target_string = "old value";
  27.         string source_string = MakeString();
  28.  
  29.         target_string = source_string;
  30.     }
  31.  
  32.     {
  33.         LOG_DURATION("assignment, without variable");
  34.  
  35.         string target_string = "old value";
  36.          
  37.         target_string = MakeString();
  38.     }
  39.  
  40.     {
  41.         LOG_DURATION("set::insert, with variable");
  42.  
  43.         set<string> strings;
  44.         string heavy_string = MakeString();
  45.         strings.insert(heavy_string);
  46.     }
  47.  
  48.     {
  49.         LOG_DURATION("set::insert, without variable");
  50.  
  51.         set<vector<int>> vectors;
  52.         strings.insert(MakeString());
  53.     }
  54.  
  55.     {
  56.         LOG_DURATION("set::insert for vector, with variable");
  57.  
  58.         set<vector<int>> vectors;
  59.         vector<int> heavy_vector = MakeVector();
  60.         vectors.insert(heavy_vector);
  61.     }
  62.  
  63.     {
  64.         LOG_DURATION("set::insert for vector, without variable");
  65.  
  66.         set<vector<int>> vectors;
  67.         vectors.insert(MakeVector());
  68.     }
  69.  
  70.     {
  71.         LOG_DURATION("map::operator[], with variables");
  72.  
  73.         map<string,string> strings;
  74.         string key = MakeString();
  75.         string value = MakeString();
  76.         strings[key] = value;
  77.     }
  78.  
  79.     {
  80.         LOG_DURATION("map::operator[], without variables");
  81.  
  82.         map<string, string> strings;
  83.    
  84.         strings[MakeString()] = MakeString();
  85.     }
  86.  
  87.     return 0;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement