How internal swap happens?

How internal swap happens?

Given two vectors v1 and v2, we can swap the contents of the two vectors manually using a O(N + M) time algorithm where N = v1.size() and M = v2.size().

However the vector class provides an inbuilt function swap().

What is the time complexity of v1.swap(v2) ?

O(N)

O(1)

O(M)

O(N + M)

Here it is written that it takes constant time. It might be just changing names of the vector.
lets say
v1 = {1,2,3,4};
v2 = {1,2};
after swapping =>
v2 = {1,2,3,4}
v1 = {1,2}
so v1 and v2 now points to different vector, without accessing the elements of the vector.

You can also read the official document from here
http://www.cplusplus.com/reference/vector/vector/swap/

isn’t this should happen when vector is passed as value?

Here we doesn’t have function defination of swap function
So we can’t comment how it is passed?
by value or by reference

okay, got it. thanks for clarifying my doubt!

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

Okay kindly give your feedback