我目前正在學習STL,並且對find和const iterators有一些不確定性。 比方說,我有一個查找功能:C++ STL,常量迭代器,find()
some_stl_container::const_iterator found = myContainer.find(value);
之後,我應該檢查什麼,我得到了found
對另一常量性,或者是 有效做出對證簡單的迭代器。 基本上會有這樣做有什麼區別:這
if(found!=myContainer.cend())
:
if(found!=myContainer.end())
第一看上去更加準確的(至少對我來說),但第二個應該正常工作過,對吧?
[const to non-const iterator_comparatoron,它們是否有效]的可能重複(http://stackoverflow.com/questions/16900498/const-to-non-const-iterator-comparisons-are-they-有效的) – juanchopanza
考慮到cend在C++ 11之前並不存在,所以必須有*某種方式來實現它。 –