方案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