大家讲道理2017-04-17 13:48:21
For example, vector
is often implemented using arrays, so the swap
function just exchanges the arrays inside the two. .
For example, there is
vector a{ 1, 2, 3, 4, 5 }; // ptr -> [1, 2, 3, 4, 5] 内部大约是这样子
vector b{ 6, 7, 8, 9, 10}; // ptr -> [6, 7, 8, 9, 10]
When we do a.swap(b)
, we just exchange the pointing of the internal pointer ptr
. .