c++ - “swap 只是交换了两个容器的内部数据结构”是什么意思?
天蓬老师
天蓬老师 2017-04-17 13:46:21
0
1
584

《C++ Primer》第五版,中文版。303 页。

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(1)
大家讲道理

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. .

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template