C++ TRICK FOR COMPETITIVE PART-10














































C++ TRICK FOR COMPETITIVE PART-10



MOVE 

When you work with STL containers like vectors, you can use the move function to just move the container, not to copy it all.

EXAMPLE

vector<int> v = {1, 2, 3, 4};
vector<int> w = move(v);

cout << "v: ";
for (auto i: v)
    cout << i << ' ';

cout << "\nw: ";
for (auto i: w)
    cout << i << ' ';
Output:
v: 
w: 1 2 3 4 

As you can see v moved to w and not copied.


Comments

  • Khushi
    15-Dec-2020 06:08:54 PM
    Nice