c++ - 同一集合上的两个不同迭代器是否相等

标签 c++ stl iterator

假设我使用嵌套的 for 来比较同一列表中的对象:

for( list<Object>::iterator iter = list.begin() ; iter != list.end() ; ++iter )
  {
    for( list<Object>::iterator iter2 = list.begin() ; iter2 != list.end() ; ++iter2 )
    {
      if( iter == iter2 )
      {
        // does this mean iter is pointing to the same INDEX
        // as iter2?  Will this work as expected?
      }
    }
  }

最佳答案

... to compare objects in the same list:

是的,这正是您所期望的,并且工作正常。

关于c++ - 同一集合上的两个不同迭代器是否相等,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13125645/

相关文章:

c++ - 对映射中的lower_bound和upper_bound

c++ - += 一对运算符和 make_pair 与模板

java - 如何通过使用 OpenCsv 记录无效记录的错误来创建有效 CSV 记录的列表?

c++ - 递增迭代器 : Is++it more efficient than it++?

c++ - 外部变量是否初始化为其默认值?

java - 为什么向下转换在 C++ 中是一种不好的做法,而不是在另一种语言中?

C++ std::vector emplace vs insert

c++ - EXC 对迭代器的错误访问

c++ - 指针递增查询

c++ - 共享指针 : pointer to pointer