方案A:迭代器和const_iterator之间的比较效率低下吗?
const auto end = whatever.end();
for (auto it = whatever.begin(); it != end; ++it)
{
// ...
}
变种b:
const auto end = whatever.cend(); // note the call to cend insteand of end here
for (auto it = whatever.begin(); it != end; ++it)
{
// ...
}
有什么理由相信变种b会比变体的效率较低,因为循环条件比较了两种不同类型的迭代器?这是否会导致it
上的隐式转换?
(end
多次使用内部的for循环中,因此,我希望葫芦出来。)
什么容器? – 2012-07-06 13:53:08
@David在我的具体情况下,它是一个'std :: string',但我一般都很好奇。 – fredoverflow 2012-07-06 13:54:40