变量a:
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的效率会低于变体a?这会在it
上导致隐式转换吗?
(由于在for循环内部多次使用end
,所以我想将其提升出来。)
std::string
,但我一般很好奇。 - fredoverflow