一般来说,为了效率和速度的目的,缓存一个结束迭代器(特别是STL容器)是一个好主意吗?例如在以下代码位中:缓存结束迭代器 - 好主意还是坏主意?
std::vector<int> vint;
const std::vector<int>::const_iterator end = vint.end();
std::vector<int>::iterator it = vint.begin();
while (it != end)
{
....
++it;
}
在什么情况下会使最终值失效?将从容器中删除原因结束被取消全部 STL容器还是只是一些?
首先问自己,你的分析器告诉你std :: vector :: end()的调用花费了大量的处理时间吗? –
daramarak
2010-06-21 12:34:50