我一直在使用std::iter_swap交换两个迭代器引用的元素.我只是想知道如果其中一个迭代器是过去的迭代器,它的效果会是什么样的效果end().
例如:
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
vector<int> is = { 1 };
cout << "Before: " << is.at(0) << endl;
iter_swap(is.begin(), is.end());
cout << "After: " << is.at(0) << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
Before: 1
After: 0
Run Code Online (Sandbox Code Playgroud)
很明显,1已经在某处交换了,但这看起来有点奇怪.
1现在在哪里?0从何而来?它是end()迭代器的表示吗?我想它也可能是int默认构造的默认值?vector?| 归档时间: |
|
| 查看次数: |
184 次 |
| 最近记录: |