Advertisement
RobertDeMilo

RB5.3 Функция move

Apr 17th, 2024
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.28 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <sstream>
  4. #include <string>
  5. #include <vector>
  6. #include <utility>
  7.  
  8. using namespace std;
  9.  
  10. vector<string> ReadStrings(istream& stream, bool use_move)
  11. {
  12.     vector<string> strings;
  13.     string s;
  14.  
  15.     while (stream >> s)
  16.     {
  17.         if (use_move)
  18.         {
  19.             //cout << "s = " << s << "\n";
  20.             strings.push_back(move(s));
  21.             //cout << "s = " << s << ", strings.back() = " << strings.back() << "\n";
  22.         }
  23.         else
  24.         {
  25.             strings.push_back(s);
  26.         }
  27.     }
  28.  
  29.     return strings;
  30. }
  31.  
  32. string GenerateText()
  33. {
  34.     const int SIZE = 1'000'000'000;
  35.    const int WORLD_LENGTH = 10'000'000;
  36.    string text(SIZE,'a');
  37.  
  38.    for (int i = WORLD_LENGTH; i < SIZE; i += WORLD_LENGTH)
  39.    {
  40.        text[i] = ' ';
  41.    }
  42.    return text;
  43. }
  44.  
  45. int main()
  46. {
  47.    /*for (const string& s : ReadStrings(cin))
  48.    {
  49.        cout << s << "\n";
  50.    }*/
  51.  
  52.    const string text = GenerateText();
  53.  
  54.    {
  55.        //LOG_DURATION("without move");
  56.  
  57.        istringstream stream(text);
  58.        ReadStrings(stream, false);
  59.    }
  60.  
  61.    {
  62.        //LOG_DURATION("with move");
  63.  
  64.        istringstream stream(text);
  65.        ReadStrings(stream, true);
  66.    }
  67.    
  68.    return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement