For summary of swap () function

Sources from Baidu Encyclopedia

Many computer swap function, such as string exchange (swap)
swap operation to achieve switching functions for all the elements in the two containers. The type of container to be exchanged must match: the container must be of the same type, the element type and the same must also be stored. After calling the swap function, the original right operand is stored in the storage elements in the left operand, and vice versa.
vector<string> svec1(10); //vector vith 10 elements
vector<string> svec2(24); //vector with 24 elements
svec1.swap(svec2);
After performing swap, the storage container 24 svec1 string types of elements, and is stored svec2 10 elements.
An important issue is that the swap: This does not remove or insert any element, but also ensure the realization of exchange in constant time. In the absence of any element within the container movement, so iterator does not fail.

Guess you like

Origin www.cnblogs.com/awangkuo/p/12534310.html