《C++ Primer》第五版,中文版。303 页。
欢迎选择我的课程,让我们一起见证您的进步~~
For example, vector is often implemented using arrays, so the swap function just exchanges the arrays inside the two. . For example, there is
vector
swap
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. .
a.swap(b)
ptr
For example,
vector
is often implemented using arrays, so theswap
function just exchanges the arrays inside the two. .For example, there is
When we do
a.swap(b)
, we just exchange the pointing of the internal pointerptr
. .