Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Если у объекта много данных на стеке, перемещение не поможет или поможет плохо
- Вызов move для константного объекта бесполезен. Следите за константностью перемещаемого объекта.
- //#include <iostream>
- //#include <vector>
- //#include <array>
- //using namespace std;
- //const int SIZE = 10'000;
- //array<int, SIZE> MakeArray()
- //{
- // array<int, SIZE> a;
- // a.fill(8);
- // return a;
- //}
- //
- //int main()
- //{
- // {
- // LOG_DURATION("with variable");
- //
- // vector<array<int, SIZE>> arrays;
- // for (int i = 0; i < 10000; ++i)
- // {
- // auto heavy_array = MakeArray();
- // arrays.push_back(heavy_array);
- // }
- // }
- // {
- // LOG_DURATION("without variable");
- //
- // vector<array<int, SIZE>> arrays;
- // for (int i = 0; i < 10000; ++i)
- // {
- // arrays.push_back(MakeArray());
- // }
- //
- // }
- //
- // return 0;
- //}
- #include <iostream>
- #include <string>
- #include <vector>
- #include <utility>
- using namespace std;
- string MakeString()
- {
- return "C++";
- }
- int main()
- {
- vector<string> strings;
- const string s = MakeString();
- cout << s << "\n";
- strings.push_back(move(s));
- cout << s << "\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement